Last active
December 19, 2015 00:48
-
-
Save ericclemmons/5870876 to your computer and use it in GitHub Desktop.
Browserify seems to not be able to reference the same module if there are different paths (because of subdirectories?) Previously: Difficulty with dynamic components in React. Form (works) -> Field (works) -> Text (fails with "Object [object Object] has no method 'value' ). Apparently the mixins don't get mixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var FieldMixin = { | |
value: function() { | |
return 'default value'; | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var FieldMixin = require('../mixins/field-mixin'); // Notice the path (1 level) | |
var Fields = { | |
'text': require('./fields/text.jsx') | |
}; | |
var Field = React.createClass({ | |
mixins: [FieldMixin], | |
render: function() { | |
var field = Fields[this.props.type]; | |
var component = field(this.props); | |
return ( | |
<div class="row"> | |
<label>Default value: {this.value()}</label> | |
{component} | |
</div> | |
); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var FieldMixin = require('../../mixins/field-mixin'); // Notice the path (2 levels) | |
var Text = React.createClass({ | |
mixins: [FieldMixin], | |
render: function() { | |
return ( | |
<input type="text" value={this.value()} /> | |
); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Request dynamic "text" template | |
var Form = React.createClass({ | |
render: function() { | |
return ( | |
<form> | |
<Field type="text" /> | |
</form> | |
); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm using Browserify for pulling in
require('field-mixin.js')
.