UNPKG

strikejs-react

Version:

A state management framework for ReactJS applications.

1,393 lines (1,292 loc) 797 kB
(function(FuseBox){FuseBox.$fuse$=FuseBox; var __process_env__ = {"NODE_ENV":"development"}; FuseBox.pkg("default", {}, function(___scope___){ ___scope___.file("examples/Basic.jsx", function(exports, require, module, __filename, __dirname){ "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var ControllerView_1 = require("../ControllerView"); var LocalStoragePersistentStrategy_1 = require("../LocalStoragePersistentStrategy"); var Store_1 = require("../Store"); var React = require("react"); var ReactDOM = require("react-dom"); var Dino = (function (_super) { __extends(Dino, _super); function Dino(p) { var _this = _super.call(this, p) || this; _this.onChange = _this.onChange.bind(_this); return _this; } Dino.prototype.onChange = function (e) { var el = e.currentTarget; this.props.onChange(el.value); }; Dino.prototype.render = function () { return (React.createElement("div", { className: "bit" }, React.createElement("div", { className: "input" }, React.createElement("input", { type: "number", onChange: this.onChange, value: this.props.value }), this.props.name))); }; return Dino; }(React.Component)); function onChange(e) { } var Basic = (function (_super) { __extends(Basic, _super); function Basic(props) { var _this = _super.call(this, props) || this; _this.onChange = _this.onChange.bind(_this); _this.onClick = _this.onClick.bind(_this); return _this; } Basic.prototype.componentDidMount = function () { // console.log(this.props); }; Basic.prototype.onClick = function () { this.props.store.dispatch({ type: 1, data: 2222 }, function () { console.log('callback'); }); }; Basic.prototype.onChange = function (txt) { this.props.store.dispatch(function (dispatch, getState) { return dispatch({ type: 1, data: txt }); }).then(function () { console.log("this is the function resolved: "); }); }; // componentWillReceiveProps(){ // this.props.dispatch(act2); // } Basic.prototype.render = function () { var data = this.props.data; return (React.createElement("div", { className: "container" }, React.createElement("div", { onClick: this.onClick }, "Click me"), React.createElement(Dino, { name: data.name, onChange: this.onChange, value: data.input }))); }; return Basic; }(React.Component)); var cx = LocalStoragePersistentStrategy_1.localStorageStrategy(); var div = document.createElement('div'); document.body.appendChild(div); var store = Store_1.createStore({ trackChanges: false, middlewares: [] }); var CV = ControllerView_1.createControllerView({ component: Basic, propsToPropagate: ['namex'], initialState: function (props) { return { input: 10, }; }, propsToData: function (props, state) { return { name: props.namex }; }, reducer: function (state, action) { var input = state.$get('input'); switch (action.type) { case 1: state.$set('input', input + 1); break; case 2: state.$set('input', input + 1000); break; } }, stateKey: 'basic' }); ReactDOM.render(React.createElement(CV, { store: store, namex: 'Suhail 2', injector: null, persistenceStrategy: cx }), div); var i = 0; var count = 0; function act(dispatch, getState, box) { var k = getState('basic'); console.log(k); store.dispatch({ type: 1, data: i }); store.dispatch({ type: 1, data: i }, function () { console.log('callback'); }); setTimeout(function () { store.dispatch(act2); store.dispatch({ type: 1, data: i }); store.dispatch(act2); }); } function act2(dispatch, getState) { store.dispatch({ type: 1, data: i }); new Promise(function (resolve) { setTimeout(function () { resolve(); }, 5000); }) .then(function () { store.dispatch({ type: 2, data: 1 }); }); store.dispatch({ type: 1, data: i }); } function tick() { count++; if (count == 10) { i++; store.dispatch(act, 1); count = 0; } // requestAnimationFrame(tick); } // requestAnimationFrame(tick); setTimeout(function () { ReactDOM.unmountComponentAtNode(div); }, 5000000); }); ___scope___.file("ControllerView.jsx", function(exports, require, module, __filename, __dirname){ "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __assign = (this && this.__assign) || Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; Object.defineProperty(exports, "__esModule", { value: true }); var React = require("react"); function createControllerView(_a) { var component = _a.component, reducer = _a.reducer, initialState = _a.initialState, deps = _a.deps, propsModifier = _a.propsModifier, propsToPropagate = _a.propsToPropagate, propsToData = _a.propsToData, stateKey = _a.stateKey; var store = null; var injector = null; var propsObject = { data: null, store: null, dispatch: null }; return (function (_super) { __extends(class_1, _super); function class_1(props) { var _this = _super.call(this, props) || this; _this.state = typeof initialState === "function" ? initialState(props) : initialState; store = props.store; propsObject.store = props.store; propsObject.dataStore = props.dataStore; propsObject.dispatch = store.dispatch; propsObject.router = props.router; _this.propagateProps(props); if (deps && injector) { if (deps instanceof Array) { deps.forEach(function (e) { propsObject[e] = injector.get(e); }); } else if (typeof deps === "object") { for (var kk in deps) { propsObject[deps[kk]] = injector.get(kk); } } } return _this; } class_1.prototype.propagateProps = function (props) { propsObject.routeParams = props.routeParams; if (propsToPropagate instanceof Array) { propsToPropagate.forEach(function (e) { propsObject[e] = props[e]; }); } if (typeof propsModifier === "function") { propsModifier(props, propsObject); } }; class_1.prototype.getStateKey = function () { return stateKey; }; class_1.prototype.getReducer = function () { return reducer; }; class_1.prototype.componentWillReceiveProps = function (props) { this.propagateProps(props); }; class_1.prototype.componentWillMount = function () { store.connect(this); }; class_1.prototype.componentDidMount = function () { var _this = this; var persistenceStrategy = this.props.persistenceStrategy; if (persistenceStrategy) { if (typeof persistenceStrategy === "function") { persistenceStrategy(stateKey, function (err, data) { if (err) { console.error(err.message, err.stack); return; } _this.setState(data); }); } else if (typeof persistenceStrategy === "object") { var persist = persistenceStrategy; if (typeof persist.get === "function") { if (persist.get.length === 2) { persist.get(stateKey, function (err, data) { if (err) { throw err; } _this.setState(data); }); } else if (persist.get.length === 1) { return persist.get(stateKey).then(function (data) { _this.setState(data); }, function (err) { console.log(err); }); } } } } }; class_1.prototype.componentWillUnmount = function () { var _this = this; var state = this.state; var persistenceStrategy = this.props.persistenceStrategy; if (typeof persistenceStrategy === "function") { persistenceStrategy(stateKey, state, function (err, data) { store.disconnect(_this); if (err) { throw err; } }); return; } else if (typeof persistenceStrategy === "object" && persistenceStrategy.get !== "undefined") { var p = persistenceStrategy; if (p.put.length === 2) { p.put(stateKey, state).then(function (data) { store.disconnect(_this); }, function (err) { console.log(err); }); return; } else if (p.put.length === 3) { p.put(stateKey, state, function (err, data) { store.disconnect(_this); if (err) { throw err; } }); return; } } store.disconnect(this); }; class_1.prototype.render = function () { var k = propsObject.data = typeof propsToData === "function" ? (__assign({}, (this.state || {}), propsToData(propsObject, this.state))) : this.state; return React.createElement(component, propsObject, this.props.children); }; return class_1; }(React.Component)); } exports.createControllerView = createControllerView; }); ___scope___.file("LocalStoragePersistentStrategy.js", function(exports, require, module, __filename, __dirname){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * Creates a persistence storage based on the localStorage. * @returns {PersistenceStrategy} */ function localStorageStrategy() { function get(key) { return new Promise(function (resolve, reject) { var v = localStorage.getItem(key); if (v) { resolve(JSON.parse(v)); return; } reject(); }); } function put(key, data) { return new Promise(function (resolve, reject) { localStorage.setItem(key, JSON.stringify(data)); resolve(); }); } return { get: get, put: put }; } exports.localStorageStrategy = localStorageStrategy; }); ___scope___.file("Store.js", function(exports, require, module, __filename, __dirname){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var Pool_1 = require("./Pool"); var ManagedState_1 = require("./ManagedState"); /** * Returns value at a given key with in an object literal. * * @export * @param {object} object the object to use * @param {string} path the path to return its value * @param {string} p path separator, defaults to '.' * @returns {any} the value at the given key */ function getDataAt(object, path, p) { var o = object, key, temp, pathSep = p ? p : '.', list = path.split(pathSep); while ((key = list.shift()) && (temp = o[key]) && (o = temp)) ; return temp; } exports.getDataAt = getDataAt; /** * Creates a state container instance with the provided configurations * @param {StoreCfg} cfg the store configurations. * @returns {IStore} */ function createStore(cfg) { var components = {}; var actions = {}; var backlog = []; var middlewares = cfg.middlewares || []; var trackChanges = typeof cfg.trackChanges === "undefined" ? false : cfg.trackChanges; var o = null; var state = {}; var pool = Pool_1.createPool(ManagedState_1.createManagedState); function connect(el) { var key = el.getStateKey(); components[key] = el; state[key] = el.state || {}; return o; } function disconnect(el) { delete components[el.getStateKey()]; delete state[el.getStateKey()]; return o; } function getStateAt(key) { return getDataAt(state, key, '.'); //state[key]; } function setStateAt(key, val) { if (components[key]) { state[key] = val; components[key].setState(state[key]); return o; } throw new Error("Component with key " + key + " could not be found"); } function applyMiddleware(action, done) { var idx = 0; var m = null; function next(action) { if (!action || idx >= middlewares.length) { return done(action); } m = middlewares[idx]; idx++; return m(action, o, next); } next(action); } function doExecute(key, action) { var managedState = pool.get(); var component = components[key]; managedState.setState(state[key]); var rd = component.getReducer(); if (rd) { rd(managedState, action); if (managedState.hasChanges()) { var changes = managedState.changes(); component.setState(function () { return changes; }, function () { action.onDone && typeof action.onDone === "function" && action.onDone(); }); } } pool.put(managedState); } function execute(action) { if (action) { if (trackChanges) { backlog.push(action); } for (var key in components) { doExecute(key, action); } } } function onAction(action, cb) { action.onDone = action.onDone || cb; if (!cb) { if (typeof Promise !== "undefined") { return new Promise(function (res) { action.onDone = res; var act = applyMiddleware(action, function (finalAction) { finalAction && execute(finalAction); }); }); } } var act = applyMiddleware(action, function (finalAction) { finalAction && execute(finalAction); }); } function onActionFail(err) { console.log(err, err.message, err.stack); } var dispatch = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } if (args.length === 0) { throw new Error("No action provided"); } else if (args.length === 1) { if (typeof args[0] === "function") { return args[0](dispatch, getStateAt); } else if (typeof args[0] === "object") { return onAction(args[0]); } } else if (args.length === 2) { if (typeof args[0] === "function") { return args[0](dispatch, getStateAt, args[1]); } else if (typeof args[0] === "object") { return onAction(args[0], args[1]); } } }; o = { connect: connect, disconnect: disconnect, getStateAt: getStateAt, setStateAt: setStateAt, dispatch: dispatch }; return o; } exports.createStore = createStore; }); ___scope___.file("Pool.js", function(exports, require, module, __filename, __dirname){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * Creates an object pool to help with object reuse. * This is to optimise garabage collection in JS application. * @param {function} make an object generator function. If provided, the function will be called when no the pool is empty. * @returns {Pool} */ function createPool(make) { var pool = []; function get(d) { if (pool.length === 0) { var v = (make && make(d)) || {}; return v; } return pool.shift(); } function put(o) { pool.push(o); } return { get: get, put: put, }; } exports.createPool = createPool; }); ___scope___.file("ManagedState.js", function(exports, require, module, __filename, __dirname){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * Creates a managed state object * @param {any} s the initial state to manage * @returns {IManagedState} */ function createManagedState(s) { var state = s || null; var _changes = {}; var o; var _hasChanges = false; function $set(key, val) { if (state[key] !== val) { _changes[key] = val; state[key] = val; _hasChanges = true; } return o; } function $get(key) { return state[key]; } function $push(key) { var args = []; for (var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments[_i]; } var data = state[key]; if (data && data.push && data.slice) { var v = data.slice(0); v.push.apply(v, args); $set(key, v); } return o; } function withMutations(cb) { cb(o); } function $splice(key, index, count) { if (count === void 0) { count = 1; } var args = []; for (var _i = 3; _i < arguments.length; _i++) { args[_i - 3] = arguments[_i]; } var data = state[key]; if (data && data.splice && data.slice) { var v = data.slice(0); v.splice.apply(v, [index, count].concat(args)); $set(key, v); } return o; } function $shift(key) { var data = state[key]; if (data && data.shift && data.slice) { var v = data.slice(0); var temp = v.shift(); $set(key, v); return temp; } return; } function $unshift(key, val) { var data = state[key]; if (data && data.unshift && data.slice) { var v = data.slice(0); v.unshift(val); $set(key, v); } return o; } function $pop(key) { var data = state[key]; if (data && data.pop && data.slice) { var v = data.slice(0); var temp = v.pop(); $set(key, v); return temp; } return; } function setState(st) { _hasChanges = false; _changes = {}; state = st; return o; } function hasChanges() { return _hasChanges; } function changes() { return _changes; } o = { setState: setState, $set: $set, $push: $push, $splice: $splice, $pop: $pop, $shift: $shift, $unshift: $unshift, $get: $get, withMutations: withMutations, hasChanges: hasChanges, changes: changes }; return o; } exports.createManagedState = createManagedState; }); }); FuseBox.pkg("fusebox-hot-reload", {}, function(___scope___){ ___scope___.file("index.js", function(exports, require, module, __filename, __dirname){ "use strict"; /** * @module listens to `source-changed` socket events and actions hot reload */ Object.defineProperty(exports, "__esModule", { value: true }); var Client = require('fusebox-websocket').SocketClient, bundleErrors = {}, outputElement = document.createElement('div'), styleElement = document.createElement('style'), minimizeToggleId = 'fuse-box-toggle-minimized', hideButtonId = 'fuse-box-hide', expandedOutputClass = 'fuse-box-expanded-output', localStoragePrefix = '__fuse-box_'; function storeSetting(key, value) { localStorage[localStoragePrefix + key] = value; } function getSetting(key) { return localStorage[localStoragePrefix + key] === 'true' ? true : false; } var outputInBody = false, outputMinimized = getSetting(minimizeToggleId), outputHidden = false; outputElement.id = 'fuse-box-output'; styleElement.innerHTML = "\n #" + outputElement.id + ", #" + outputElement.id + " * {\n box-sizing: border-box;\n }\n #" + outputElement.id + " {\n z-index: 999999999999;\n position: fixed;\n top: 10px;\n right: 10px;\n width: 400px;\n overflow: auto;\n background: #fdf3f1;\n border: 1px solid #eca494;\n border-radius: 5px;\n font-family: \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n box-shadow: 0px 3px 6px 1px rgba(0,0,0,.15);\n }\n #" + outputElement.id + "." + expandedOutputClass + " {\n height: auto;\n width: auto;\n left: 10px;\n max-height: calc(100vh - 50px);\n }\n #" + outputElement.id + " .fuse-box-errors {\n display: none;\n }\n #" + outputElement.id + "." + expandedOutputClass + " .fuse-box-errors {\n display: block;\n border-top: 1px solid #eca494;\n padding: 0 10px;\n }\n #" + outputElement.id + " button {\n border: 1px solid #eca494;\n padding: 5px 10px;\n border-radius: 4px;\n margin-left: 5px;\n background-color: white;\n color: black;\n box-shadow: 0px 2px 2px 0px rgba(0,0,0,.05);\n }\n #" + outputElement.id + " .fuse-box-header {\n padding: 10px;\n }\n #" + outputElement.id + " .fuse-box-header h4 {\n display: inline-block;\n margin: 4px;\n }"; styleElement.type = 'text/css'; document.getElementsByTagName('head')[0].appendChild(styleElement); function displayBundleErrors() { var errorMessages = Object.keys(bundleErrors).reduce(function (allMessages, bundleName) { var bundleMessages = bundleErrors[bundleName]; return allMessages.concat(bundleMessages.map(function (message) { var messageOutput = message .replace(/\n/g, '<br>') .replace(/\t/g, '&nbsp;&nbps;&npbs;&nbps;') .replace(/ /g, '&nbsp;'); return "<pre>" + messageOutput + "</pre>"; })); }, []), errorOutput = errorMessages.join(''); if (errorOutput && !outputHidden) { outputElement.innerHTML = "\n <div class=\"fuse-box-header\" style=\"\">\n <h4 style=\"\">Fuse Box Bundle Errors (" + errorMessages.length + "):</h4>\n <div style=\"float: right;\">\n <button id=\"" + minimizeToggleId + "\">" + (outputMinimized ? 'Expand' : 'Minimize') + "</button>\n <button id=\"" + hideButtonId + "\">Hide</button>\n </div>\n </div>\n <div class=\"fuse-box-errors\">\n " + errorOutput + "\n </div>\n "; document.body.appendChild(outputElement); outputElement.className = outputMinimized ? '' : expandedOutputClass; outputInBody = true; document.getElementById(minimizeToggleId).onclick = function () { outputMinimized = !outputMinimized; storeSetting(minimizeToggleId, outputMinimized); displayBundleErrors(); }; document.getElementById(hideButtonId).onclick = function () { outputHidden = true; displayBundleErrors(); }; } else if (outputInBody) { document.body.removeChild(outputElement); outputInBody = false; } } exports.connect = function (port, uri) { if (FuseBox.isServer) { return; } port = port || window.location.port; var client = new Client({ port: port, uri: uri, }); client.connect(); client.on('source-changed', function (data) { console.info("%cupdate \"" + data.path + "\"", 'color: #237abe'); /** * If a plugin handles this request then we don't have to do anything **/ for (var index = 0; index < FuseBox.plugins.length; index++) { var plugin = FuseBox.plugins[index]; if (plugin.hmrUpdate && plugin.hmrUpdate(data)) { return; } } if (data.type === "hosted-css") { var fileId = data.path.replace(/^\//, '').replace(/[\.\/]+/g, '-'); var existing = document.getElementById(fileId); if (existing) { existing.setAttribute("href", data.path + "?" + new Date().getTime()); } else { var node = document.createElement('link'); node.id = fileId; node.type = 'text/css'; node.rel = 'stylesheet'; node.href = data.path; document.getElementsByTagName('head')[0].appendChild(node); } } if (data.type === 'js' || data.type === "css") { FuseBox.flush(); FuseBox.dynamic(data.path, data.content); if (FuseBox.mainFile) { try { FuseBox.import(FuseBox.mainFile); } catch (e) { if (typeof e === 'string') { if (/not found/.test(e)) { return window.location.reload(); } } console.error(e); } } } }); client.on('error', function (error) { console.log(error); }); client.on('bundle-error', function (_a) { var bundleName = _a.bundleName, message = _a.message; console.error("Bundle error in " + bundleName + ": " + message); var errorsForBundle = bundleErrors[bundleName] || []; errorsForBundle.push(message); bundleErrors[bundleName] = errorsForBundle; displayBundleErrors(); }); client.on('update-bundle-errors', function (_a) { var bundleName = _a.bundleName, messages = _a.messages; messages.forEach(function (message) { return console.error("Bundle error in " + bundleName + ": " + message); }); bundleErrors[bundleName] = messages; displayBundleErrors(); }); }; }); return ___scope___.entry = "index.js"; }); FuseBox.pkg("fusebox-websocket", {}, function(___scope___){ ___scope___.file("index.js", function(exports, require, module, __filename, __dirname){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var events = require('events'); var SocketClient = /** @class */ (function () { function SocketClient(opts) { opts = opts || {}; var port = opts.port || window.location.port; var protocol = location.protocol === 'https:' ? 'wss://' : 'ws://'; var domain = location.hostname || 'localhost'; this.url = opts.host || "" + protocol + domain + ":" + port; if (opts.uri) { this.url = opts.uri; } this.authSent = false; this.emitter = new events.EventEmitter(); } SocketClient.prototype.reconnect = function (fn) { var _this = this; setTimeout(function () { _this.emitter.emit('reconnect', { message: 'Trying to reconnect' }); _this.connect(fn); }, 5000); }; SocketClient.prototype.on = function (event, fn) { this.emitter.on(event, fn); }; SocketClient.prototype.connect = function (fn) { var _this = this; console.log('%cConnecting to fusebox HMR at ' + this.url, 'color: #237abe'); setTimeout(function () { _this.client = new WebSocket(_this.url); _this.bindEvents(fn); }, 0); }; SocketClient.prototype.close = function () { this.client.close(); }; SocketClient.prototype.send = function (eventName, data) { if (this.client.readyState === 1) { this.client.send(JSON.stringify({ event: eventName, data: data || {} })); } }; SocketClient.prototype.error = function (data) { this.emitter.emit('error', data); }; /** Wires up the socket client messages to be emitted on our event emitter */ SocketClient.prototype.bindEvents = function (fn) { var _this = this; this.client.onopen = function (event) { console.log('%cConnected', 'color: #237abe'); if (fn) { fn(_this); } }; this.client.onerror = function (event) { _this.error({ reason: event.reason, message: 'Socket error' }); }; this.client.onclose = function (event) { _this.emitter.emit('close', { message: 'Socket closed' }); if (event.code !== 1011) { _this.reconnect(fn); } }; this.client.onmessage = function (event) { var data = event.data; if (data) { var item = JSON.parse(data); _this.emitter.emit(item.type, item.data); _this.emitter.emit('*', item); } }; }; return SocketClient; }()); exports.SocketClient = SocketClient; }); return ___scope___.entry = "index.js"; }); FuseBox.pkg("events", {}, function(___scope___){ ___scope___.file("index.js", function(exports, require, module, __filename, __dirname){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to permit // persons to whom the Software is furnished to do so, subject to the // following conditions: // // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // USE OR OTHER DEALINGS IN THE SOFTWARE. if (FuseBox.isServer) { module.exports = global.require("events"); } else { function EventEmitter() { this._events = this._events || {}; this._maxListeners = this._maxListeners || undefined; } module.exports = EventEmitter; // Backwards-compat with node 0.10.x EventEmitter.EventEmitter = EventEmitter; EventEmitter.prototype._events = undefined; EventEmitter.prototype._maxListeners = undefined; // By default EventEmitters will print a warning if more than 10 listeners are // added to it. This is a useful default which helps finding memory leaks. EventEmitter.defaultMaxListeners = 10; // Obviously not all Emitters should be limited to 10. This function allows // that to be increased. Set to zero for unlimited. EventEmitter.prototype.setMaxListeners = function(n) { if (!isNumber(n) || n < 0 || isNaN(n)) throw TypeError("n must be a positive number"); this._maxListeners = n; return this; }; EventEmitter.prototype.emit = function(type) { var er, handler, len, args, i, listeners; if (!this._events) this._events = {}; // If there is no 'error' event listener then throw. if (type === "error") { if (!this._events.error || (isObject(this._events.error) && !this._events.error.length)) { er = arguments[1]; if (er instanceof Error) { throw er; // Unhandled 'error' event } throw TypeError("Uncaught, unspecified \"error\" event."); } } handler = this._events[type]; if (isUndefined(handler)) return false; if (isFunction(handler)) { switch (arguments.length) { // fast cases case 1: handler.call(this); break; case 2: handler.call(this, arguments[1]); break; case 3: handler.call(this, arguments[1], arguments[2]); break; // slower default: args = Array.prototype.slice.call(arguments, 1); handler.apply(this, args); } } else if (isObject(handler)) { args = Array.prototype.slice.call(arguments, 1); listeners = handler.slice(); len = listeners.length; for (i = 0; i < len; i++) listeners[i].apply(this, args); } return true; }; EventEmitter.prototype.addListener = function(type, listener) { var m; if (!isFunction(listener)) throw TypeError("listener must be a function"); if (!this._events) this._events = {}; // To avoid recursion in the case that type === "newListener"! Before // adding it to the listeners, first emit "newListener". if (this._events.newListener) this.emit("newListener", type, isFunction(listener.listener) ? listener.listener : listener); if (!this._events[type]) // Optimize the case of one listener. Don't need the extra array object. this._events[type] = listener; else if (isObject(this._events[type])) // If we've already got an array, just append. this._events[type].push(listener); else // Adding the second element, need to change to array. this._events[type] = [this._events[type], listener]; // Check for listener leak if (isObject(this._events[type]) && !this._events[type].warned) { if (!isUndefined(this._maxListeners)) { m = this._maxListeners; } else { m = EventEmitter.defaultMaxListeners; } if (m && m > 0 && this._events[type].length > m) { this._events[type].warned = true; console.error("(node) warning: possible EventEmitter memory " + "leak detected. %d listeners added. " + "Use emitter.setMaxListeners() to increase limit.", this._events[type].length); if (typeof console.trace === "function") { // not supported in IE 10 console.trace(); } } } return this; }; EventEmitter.prototype.on = EventEmitter.prototype.addListener; EventEmitter.prototype.once = function(type, listener) { if (!isFunction(listener)) throw TypeError("listener must be a function"); var fired = false; function g() { this.removeListener(type, g); if (!fired) { fired = true; listener.apply(this, arguments); } } g.listener = listener; this.on(type, g); return this; }; // emits a 'removeListener' event iff the listener was removed EventEmitter.prototype.removeListener = function(type, listener) { var list, position, length, i; if (!isFunction(listener)) throw TypeError("listener must be a function"); if (!this._events || !this._events[type]) return this; list = this._events[type]; length = list.length; position = -1; if (list === listener || (isFunction(list.listener) && list.listener === listener)) { delete this._events[type]; if (this._events.removeListener) this.emit("removeListener", type, listener); } else if (isObject(list)) { for (i = length; i-- > 0;) { if (list[i] === listener || (list[i].listener && list[i].listener === listener)) { position = i; break; } } if (position < 0) return this; if (list.length === 1) { list.length = 0; delete this._events[type]; } else { list.splice(position, 1); } if (this._events.removeListener) this.emit("removeListener", type, listener); } return this; }; EventEmitter.prototype.removeAllListeners = function(type) { var key, listeners; if (!this._events) return this; // not listening for removeListener, no need to emit if (!this._events.removeListener) { if (arguments.length === 0) this._events = {}; else if (this._events[type]) delete this._events[type]; return this; } // emit removeListener for all listeners on all events if (arguments.length === 0) { for (key in this._events) { if (key === "removeListener") continue; this.removeAllListeners(key); } this.removeAllListeners("removeListener"); this._events = {}; return this; } listeners = this._events[type]; if (isFunction(listeners)) { this.removeListener(type, listeners); } else if (listeners) { // LIFO order while (listeners.length) this.removeListener(type, listeners[listeners.length - 1]); } delete this._events[type]; return this; }; EventEmitter.prototype.listeners = function(type) { var ret; if (!this._events || !this._events[type]) ret = []; else if (isFunction(this._events[type])) ret = [this._events[type]]; else ret = this._events[type].slice(); return ret; }; EventEmitter.prototype.listenerCount = function(type) { if (this._events) { var evlistener = this._events[type]; if (isFunction(evlistener)) return 1; else if (evlistener) return evlistener.length; } return 0; }; EventEmitter.listenerCount = function(emitter, type) { return emitter.listenerCount(type); }; function isFunction(arg) { return typeof arg === "function"; } function isNumber(arg) { return typeof arg === "number"; } function isObject(arg) { return typeof arg === "object" && arg !== null; } function isUndefined(arg) { return arg === void 0; } } }); return ___scope___.entry = "index.js"; }); FuseBox.pkg("react", {}, function(___scope___){ ___scope___.file("react.js", function(exports, require, module, __filename, __dirname){ 'use strict'; module.exports = require('./lib/React'); }); ___scope___.file("lib/React.js", function(exports, require, module, __filename, __dirname){ /* fuse:injection: */ var process = require("process"); /** * Copyright 2013-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * */ 'use strict'; var _assign = require('object-assign'); var ReactBaseClasses = require('./ReactBaseClasses'); var ReactChildren = require('./ReactChildren'); var ReactDOMFactories = require('./ReactDOMFactories'); var ReactElement = require('./ReactElement'); var ReactPropTypes = require('./ReactPropTypes'); var ReactVersion = require('./ReactVersion'); var createReactClass = require('./createClass'); var onlyChild = require('./onlyChild'); var createElement = ReactElement.createElement; var createFactory = ReactElement.createFactory; var cloneElement = ReactElement.cloneElement; if (process.env.NODE_ENV !== 'production') { var lowPriorityWarning = require('./lowPriorityWarning'); var canDefineProperty = require('./canDefineProperty'); var ReactElementValidator = require('./ReactElementValidator'); var didWarnPropTypesDeprecated = false; createElement = ReactElementValidator.createElement; createFactory = ReactElementValidator.createFactory; cloneElement = ReactElementValidator.cloneElement; } var __spread = _assign; var createMixin = function (mixin) { return mixin; }; if (process.env.NODE_ENV !== 'production') { var warnedForSpread = false; var warnedForCreateMixin = false; __spread = function () { lowPriorityWarning(warnedForSpread, 'React.__spread is deprecated and should not be used. Use ' + 'Object.assign directly or another helper function with similar ' + 'semantics. You may be seeing this warning due to your compiler. ' + 'See https://fb.me/react-spread-deprecation for more details.'); warnedForSpread = true; return _assign.apply(null, arguments); }; createMixin = function (mixin) { lowPriorityWarning(warnedForCreateMixin, 'React.createMixin is deprecated and should not be used. ' + 'In React v16.0, it will be removed. ' + 'You can use this mixin directly instead. ' + 'See https://fb.me/createmixin-was-never-implemented for more info.'); warnedForCreateMixin = true; return mixin; }; } var React = { // Modern Children: { map: ReactChildren.map, forEach: ReactChildren.forEach, count: ReactChildren.count, toArray: ReactChildren.toArray, only: onlyChild }, Component: ReactBaseClasses.Component, PureComponent: ReactBaseClasses.PureComponent, createElement: createElement, cloneElement: cloneElement, isValidElement: ReactElement.isValidElement, // Classic PropTypes: ReactPropTypes, createClass: createReactClass, createFactory: createFactory, createMixin: createMixin, // This looks DOM specific but these are actually isomorphic helpers // since they are just generating DOM strings. DOM: ReactDOMFactories, version: ReactVersion, // Deprecated hook for JSX spread, don't use this for anything. __spread: __spread }; if (process.env.NODE_ENV !== 'production') { var warnedForCreateClass = false; if (canDefineProperty) { Object.defineProperty(React, 'PropTypes', { get: function () { lowPriorityWarning(didWarnPropTypesDeprecated, 'Accessing PropTypes via the main React package is deprecated,' + ' and will be removed in React v16.0.' + ' Use the latest available v15.* prop-types package from npm instead.' + ' For info on usage, compatibility, migration and more, see ' + 'https://fb.me/prop-types-docs'); didWarnPropTypesDeprecated = true; return ReactPropTypes; } }); Object.defineProperty(React, 'createClass', { get: function () { lowPriorityWarning(warnedForCreateClass, 'Accessing createClass via the main React package is deprecated,' + ' and will be removed in React v16.0.' + " Use a plain JavaScript class instead. If you're not yet " + 'ready to migrate, create-react-class v15.* is available ' + 'on npm as a temporary, drop-in replacement. ' + 'For more info see https://fb.me/react-create-class'); warnedForCreateClass = true; return createReactClass; } }); } // React.DOM factories are deprecated. Wrap these methods so that // invocations of the React.DOM namespace and alert users to switch // to the `react-dom-factories` package. React.DOM = {}; var warnedForFactories = false; Object.keys(ReactDOMFactories).forEach(function (factory) { React.DOM[factory] = function () { if (!warnedForFactories) { lowPriorityWarning(false, 'Accessing factories like React.DOM.%s has been deprecated ' + 'and will be removed in v16.0+. Use the ' + 'react-dom-factories package instead. ' + ' Version 1.0 provides a drop-in replacement.' + ' For more info, see https://fb.me/react-dom-factories', factory); warnedForFactories = true; } return ReactDOMFactories[factory].apply(ReactDOMFactories, arguments); }; }); } module.exports = React; }); ___scope___.file("lib/ReactBaseClasses.js", function(exports, require, module, __filename, __dirname){ /* fuse:injection: */ var process = require("process"); /** * Copyright 2013-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * */ 'use strict'; var _prodInvariant = require('./reactProdInvariant'), _assign = require('object-assign'); var ReactNoopUpdateQueue = require('./ReactNoopUpdateQueue'); var canDefineProperty = require('./canDefineProperty'); var emptyObject = require('fbjs/lib/emptyObject'); var invariant = require('fbjs/lib/invariant'); var lowPriorityWarning = require('./lowPriorityWarning'); /** * Base class helpers for the updating state of a component. */ function ReactComponent(props, context, updater) { this.props = props; this.context = context; this.refs = emptyObject; // We initialize the default updater but the real one gets injected by the // renderer. this.updater = updater || ReactNoopUpdateQueue; } ReactComponent.prototype.isReactComponent = {}; /** * Sets a subset of the state. Always use this to mutate * state. You should treat `this.state` as immutable. * * There is no guarantee that `this.state` will be immediately updated, so * accessing `this.state` after calling this method may return the old value. * * There is no guarantee that calls to `setState` will run synchronously, * as they may eventually be batched together. You can provide an optional * callback that will be executed when the call to setState is actually * completed. * * When a function is provided to setState, it will be called at some point in * the future (not synchronously). It will be called with the up to date * component arguments (state, props, context). These values can be different * from this.* because your function may be called after receiveProps but before * shouldComponentUpdate, and this new state, props, and context will not yet be * assigned to this. * * @param {object|function} partialState Next partial state or function to * produce next partial state to be merged with current state. * @param {?function} callback Called after state is updated. * @final * @protected */ ReactComponent.prototype.setState = function (partialState, callback) { !(typeof partialState === 'object' || typeof partialState === 'f