JSFiddle - React, Tailwind, and code Playground
by kyllle
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.5/handlebars.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.3.3/backbone-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.1/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.1/react-dom.min.js"></script>
<script>
(function(root, factory) {
if (typeof exports === 'object') {
// CommonJS
module.exports = factory(require('backbone'), require('react'), require('underscore'));
} else if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['backbone', 'react', 'underscore'], factory);
} else {
// Browser globals
root.amdWeb = factory(root.Backbone, root.React, root._);
}
}(this, function(Backbone, React, _) {
'use strict';
var collectionBehavior = {
changeOptions: 'add remove reset sort',
updateScheduler: function(func) { return _.debounce(func, 0); }
};
var modelBehavior = {
changeOptions: 'change',
//note: if we debounce models too we can no longer use model attributes
//as properties to react controlled components due to https://github.com/facebook/react/issues/955
updateScheduler: _.identity
};
var subscribe = function(component, modelOrCollection, customChangeOptions) {
if (!modelOrCollection) {
return;
}
var behavior = React.BackboneMixin.ConsiderAsCollection(modelOrCollection) ? collectionBehavior : modelBehavior;
var triggerUpdate = behavior.updateScheduler(function() {
if (component.isMounted()) {
(component.onModelChange || component.forceUpdate).call(component);
}
});
var changeOptions = customChangeOptions || component.changeOptions || behavior.changeOptions;
modelOrCollection.on(changeOptions,...