import React, { Component, PropTypes } from 'react';
import SVGInjector from 'svg-injector';

export default class ReactSVG extends Component {

  static defaultProps = {
    evalScripts: 'never',
    callback: () => {}
  }

  static propTypes = {
    path: PropTypes.string.isRequired,
    className: PropTypes.string,
    evalScripts: PropTypes.oneOf(['always', 'once', 'never']),
    fallbackPath: PropTypes.string,
    callback: PropTypes.func
  }

  render() {

    const {
      className,
      path,
      fallbackPath
    } = this.props;

    return (
      <img
        className={className}
        data-src={path}
        data-fallback={fallbackPath}
        ref={(img) => this._img = img}
      />
    );

  }

  componentDidMount() {
    this.updateSVG();
  }

  componentDidUpdate() {
    this.updateSVG();
  }

  updateSVG() {

    const {
      evalScripts,
      callback: each
    } = this.props;

    SVGInjector(this._img, {
      evalScripts,
      each
    });

  }

}

@@ -9,16 +9,20 @@
 eact, %7B 
+Pure
 Componen
@@ -48,17 +48,16 @@
  'react'
-;
 %0Aimport 
@@ -87,17 +87,16 @@
 njector'
-;
 %0A%0Aexport
@@ -127,16 +127,20 @@
 extends 
+Pure
 Componen
@@ -178,52 +178,70 @@
     
-evalScripts: 'never',%0A    callback: () =%3E %7B%7D
+callback: () =%3E %7B%7D,%0A    className: '',%0A    evalScripts: 'once'
 %0A  %7D
@@ -269,20 +269,24 @@
 = %7B%0A    
-path
+callback
 : PropTy
@@ -293,25 +293,12 @@
 pes.
-string.isRequired
+func
 ,%0A  
@@ -362,16 +362,17 @@
 .oneOf(%5B
+ 
 'always'
@@ -392,16 +392,17 @@
 ver'
+ 
 %5D),%0A    
 fall
@@ -393,32 +393,27 @@
 er' %5D),%0A    
-fallback
+src
 Path: PropTy
@@ -426,58 +426,41 @@
 ring
-,%0A    callback: PropTypes.func%0A  %7D%0A%0A  render
+.isRequired%0A  %7D%0A%0A  injectSVG
 () %7B%0A
-%0A
     
@@ -477,37 +477,27 @@
     
-className,%0A      path
+evalScripts
 ,%0A      
 fall
@@ -492,27 +492,29 @@
 ,%0A      
-f
+c
 allback
-Pat
+: eac
 h%0A    %7D 
@@ -529,181 +529,110 @@
 rops
-;
 %0A%0A    
-return (%0A      %3Cimg%0A        className=%7BclassName%7D%0A        data-src=%7Bpath%7D%0A        data-fallback=%7BfallbackPath%7D%0A        ref=%7B(img) =%3E this._img = img%7D
+if (this._img) %7B%0A      SVGInjector(this._img, %7B%0A        evalScripts,%0A        each
 %0A      
-/%3E
+%7D)
 %0A    
-);%0A
+%7D
 %0A  %7D
@@ -662,36 +662,35 @@
  %7B%0A    this.
-update
+inject
 SVG()
-;
 %0A  %7D%0A%0A  comp
@@ -721,28 +721,27 @@
 his.
-update
+inject
 SVG()
-;
 %0A  %7D%0A%0A  
 upda
@@ -740,23 +740,19 @@
 %0A%0A  
-updateSVG
+render
 () %7B%0A
-%0A
     
@@ -769,40 +769,31 @@
     
-evalScripts,%0A      callback: eac
+className,%0A      srcPat
 h%0A  
@@ -812,77 +812,142 @@
 rops
-;
 %0A%0A    
-SVGInjector(this._img, %7B%0A      evalScripts,%0A      each%0A    %7D);
+return (%0A      %3Cimg%0A        ref=%7Bimg =%3E this._img = img%7D%0A        className=%7BclassName%7D%0A        data-src=%7BsrcPath%7D%0A      /%3E%0A    )
 %0A%0A  

Make pure, ditch fallback png option