microcosm
Advanced tools
Comparing version 12.12.0 to 12.13.0-alpha.0
@@ -36,2 +36,3 @@ 'use strict'; | ||
this.value = {}; | ||
this.revision = 0; | ||
@@ -79,2 +80,12 @@ this.repo.on('change', this.compute, this); | ||
Model.prototype.publish = function publish (value ) { | ||
if (value !== this.value) { | ||
this.value = value; | ||
this.revision += 1; | ||
this._emit('change', this.value); | ||
} | ||
return value | ||
}; | ||
/** | ||
@@ -84,8 +95,3 @@ * Update a specific model key. Emits a change event | ||
Model.prototype.set = function set$1 (key , value ) { | ||
var next = ___microcosm_js.set(this.value, key, value); | ||
if (this.value !== next) { | ||
this.value = next; | ||
this._emit('change', this.value); | ||
} | ||
return this.publish(___microcosm_js.set(this.value, key, value)) | ||
}; | ||
@@ -102,2 +108,3 @@ | ||
var next = last; | ||
for (var key in this$1.bindings) { | ||
@@ -109,6 +116,3 @@ var value = invoke(this$1.bindings[key], this$1.repo, this$1.scope); | ||
if (last !== next) { | ||
this.value = next; | ||
this._emit('change', next); | ||
} | ||
return this.publish(next) | ||
}; | ||
@@ -115,0 +119,0 @@ |
@@ -11,2 +11,40 @@ 'use strict'; | ||
/** | ||
* Diffing algorithm for presenters. We need to recalculate the | ||
* model of props are state change, but ignore children. | ||
*/ | ||
function shallowDiff(a, b) { | ||
for (var key in a) { | ||
if (key === 'children') { | ||
continue | ||
} | ||
if (a[key] !== b[key]) { | ||
return true | ||
} | ||
} | ||
for (var key$1 in b) { | ||
if (!(key$1 in a)) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
// Cross platform request animation frame | ||
var hasFrame = typeof requestAnimationFrame !== 'undefined'; | ||
var requestFrame = setTimeout; | ||
var cancelFrame = clearTimeout; | ||
/* istanbul ignore if */ | ||
if (hasFrame) { | ||
requestFrame = requestAnimationFrame; | ||
cancelFrame = cancelAnimationFrame; | ||
} | ||
/** | ||
* @fileoverview Presenter is a specialized React component that | ||
@@ -29,4 +67,4 @@ * creates a boundary between "smart" and "dumb" components. This | ||
presenter: this, | ||
parentState: this.state, | ||
parentProps: this.props | ||
presenterProps: this.props, | ||
presenterState: this.state | ||
}) | ||
@@ -56,2 +94,3 @@ } | ||
this.send = this.send.bind(this); | ||
this.state = {}; | ||
} | ||
@@ -63,26 +102,8 @@ | ||
Presenter.prototype._beginSetup = function _beginSetup (mediator ) { | ||
this.repo = mediator.repo; | ||
this.mediator = mediator; | ||
var prototypeAccessors = { model: {} }; | ||
this.setup(this.repo, this.props, this.state); | ||
this.model = this.mediator.updateModel(this.props, this.state); | ||
this.ready(this.repo, this.props, this.state); | ||
prototypeAccessors.model.get = function () { | ||
return this.mediator.model.value | ||
}; | ||
Presenter.prototype._beginTeardown = function _beginTeardown () { | ||
this.teardown(this.repo, this.props, this.state); | ||
}; | ||
Presenter.prototype._requestRepo = function _requestRepo (contextRepo ) { | ||
var givenRepo = this.props.repo || contextRepo; | ||
var workingRepo = this.getRepo(givenRepo, this.props); | ||
this.didFork = workingRepo !== givenRepo; | ||
return workingRepo | ||
}; | ||
/** | ||
@@ -105,2 +126,9 @@ * Called when a presenter is created, useful any prep work. `setup` | ||
Presenter.prototype.componentWillUpdate = function componentWillUpdate (props , state ) { | ||
if (shallowDiff(this.props, props) || shallowDiff(this.state, state)) { | ||
this._updateModel(props, state); | ||
this.update(this.repo, props, state); | ||
} | ||
}; | ||
/** | ||
@@ -130,10 +158,5 @@ * Called when a presenter gets new props. This is useful for secondary | ||
Presenter.prototype.intercept = function intercept () { | ||
return {} | ||
return null | ||
}; | ||
Presenter.prototype.componentWillUpdate = function componentWillUpdate (props , state ) { | ||
this.model = this.mediator.updateModel(props, state); | ||
this.update(this.repo, props, state); | ||
}; | ||
/** | ||
@@ -178,2 +201,34 @@ * Runs before assigning a repo to a Presenter. This method is given | ||
// Private | ||
Presenter.prototype._updateModel = function _updateModel (props , state ) { | ||
return this.mediator.model.bind(this.getModel(props, state)) | ||
}; | ||
Presenter.prototype._beginSetup = function _beginSetup (mediator ) { | ||
this.repo = mediator.repo; | ||
this.mediator = mediator; | ||
this.setup(this.repo, this.props, this.state); | ||
this._updateModel(this.props, this.state); | ||
this.ready(this.repo, this.props, this.state); | ||
}; | ||
Presenter.prototype._beginTeardown = function _beginTeardown () { | ||
this.teardown(this.repo, this.props, this.state); | ||
}; | ||
Presenter.prototype._requestRepo = function _requestRepo (contextRepo ) { | ||
var givenRepo = this.props.repo || contextRepo; | ||
var workingRepo = this.getRepo(givenRepo, this.props); | ||
this.didFork = workingRepo !== givenRepo; | ||
return workingRepo | ||
}; | ||
Object.defineProperties( Presenter.prototype, prototypeAccessors ); | ||
return Presenter; | ||
@@ -187,11 +242,10 @@ }(React.PureComponent)); | ||
this.presenter = props.presenter; | ||
this.repo = this.presenter._requestRepo(context.repo); | ||
this.send = this.send.bind(this); | ||
this._lastRevision = -Infinity; | ||
this.state = { repo: this.repo, send: this.send }; | ||
this.model = new Model(this.repo, this.presenter); | ||
this.model.on('change', this.updateState, this); | ||
// The following methods are autobound to protect scope | ||
this.send = this.send.bind(this); | ||
this._scheduleUpdate = this._scheduleUpdate.bind(this); | ||
} | ||
@@ -217,2 +271,3 @@ | ||
this.presenter.refs = this.refs; | ||
this.model.on('change', this._queueUpdate, this); | ||
}; | ||
@@ -230,14 +285,21 @@ | ||
this.presenter._beginTeardown(); | ||
this._stopUpdate(); | ||
}; | ||
PresenterMediator.prototype.render = function render () { | ||
// setObject might have been called before the model | ||
// can get assigned | ||
this.presenter.model = this.state; | ||
// Views can be getters, so pluck it out so that it is only evaluated once | ||
var view = this.presenter.view; | ||
var ref = this.presenter; | ||
var model = ref.model; | ||
var view = ref.view; | ||
var ref$1 = this.props; | ||
var presenterProps = ref$1.presenterProps; | ||
this._lastRevision = this.model.revision; | ||
if (view != null) { | ||
return React.createElement(view, Microcosm.merge(this.presenter.props, this.state)) | ||
return React.createElement( | ||
view, | ||
Microcosm.merge(presenterProps, { repo: this.repo, send: this.send }, model) | ||
) | ||
} | ||
@@ -248,26 +310,2 @@ | ||
PresenterMediator.prototype.updateState = function updateState (state ) { | ||
this.setState(state); | ||
}; | ||
PresenterMediator.prototype.updateModel = function updateModel (props , state ) { | ||
var bindings = this.presenter.getModel(props, state); | ||
this.model.bind(bindings); | ||
return this.model.value | ||
}; | ||
PresenterMediator.prototype.getParent = function getParent () { | ||
return this.context.parent | ||
}; | ||
PresenterMediator.prototype.getHandler = function getHandler (intent ) { | ||
var interceptors = this.presenter.intercept(); | ||
// A presenter's register goes through the same registration steps | ||
// Get the first index because Presenters can not chain | ||
return Microcosm.getRegistration(interceptors, intent, 'resolve')[0] | ||
}; | ||
PresenterMediator.prototype.send = function send (intent ) { | ||
@@ -281,3 +319,3 @@ var params = [], len = arguments.length - 1; | ||
while (mediator) { | ||
var handler = mediator.getHandler(taggedIntent); | ||
var handler = mediator._getHandler(taggedIntent); | ||
@@ -288,3 +326,3 @@ if (handler) { | ||
mediator = mediator.getParent(); | ||
mediator = mediator._getParent(); | ||
} | ||
@@ -297,2 +335,41 @@ | ||
// Private | ||
PresenterMediator.prototype._scheduleUpdate = function _scheduleUpdate () { | ||
if (this.model.revision > this._lastRevision) { | ||
this.forceUpdate(); | ||
} | ||
this._scheduledFrame = null; | ||
}; | ||
PresenterMediator.prototype._queueUpdate = function _queueUpdate () { | ||
if (this.repo.history.batch) { | ||
if (!this._scheduledFrame) { | ||
this._scheduledFrame = requestFrame(this._scheduleUpdate); | ||
} | ||
} else { | ||
this.forceUpdate(); | ||
} | ||
}; | ||
PresenterMediator.prototype._stopUpdate = function _stopUpdate () { | ||
if (this._scheduledFrame) { | ||
cancelFrame(this._scheduledFrame); | ||
this._scheduledFrame = null; | ||
} | ||
}; | ||
PresenterMediator.prototype._getParent = function _getParent () { | ||
return this.context.parent | ||
}; | ||
PresenterMediator.prototype._getHandler = function _getHandler (intent ) { | ||
var interceptors = this.presenter.intercept(); | ||
// A presenter's register goes through the same registration steps | ||
// Get the first index because Presenters can not chain | ||
return Microcosm.getRegistration(interceptors, intent, 'resolve')[0] | ||
}; | ||
return PresenterMediator; | ||
@@ -299,0 +376,0 @@ }(React.PureComponent)); |
@@ -34,2 +34,3 @@ import { Emitter, set } from '../microcosm.js'; | ||
this.value = {}; | ||
this.revision = 0; | ||
@@ -77,2 +78,12 @@ this.repo.on('change', this.compute, this); | ||
Model.prototype.publish = function publish (value ) { | ||
if (value !== this.value) { | ||
this.value = value; | ||
this.revision += 1; | ||
this._emit('change', this.value); | ||
} | ||
return value | ||
}; | ||
/** | ||
@@ -82,8 +93,3 @@ * Update a specific model key. Emits a change event | ||
Model.prototype.set = function set$1 (key , value ) { | ||
var next = set(this.value, key, value); | ||
if (this.value !== next) { | ||
this.value = next; | ||
this._emit('change', this.value); | ||
} | ||
return this.publish(set(this.value, key, value)) | ||
}; | ||
@@ -100,2 +106,3 @@ | ||
var next = last; | ||
for (var key in this$1.bindings) { | ||
@@ -107,6 +114,3 @@ var value = invoke(this$1.bindings[key], this$1.repo, this$1.scope); | ||
if (last !== next) { | ||
this.value = next; | ||
this._emit('change', next); | ||
} | ||
return this.publish(next) | ||
}; | ||
@@ -113,0 +117,0 @@ |
@@ -6,2 +6,40 @@ import React from 'react'; | ||
/** | ||
* Diffing algorithm for presenters. We need to recalculate the | ||
* model of props are state change, but ignore children. | ||
*/ | ||
function shallowDiff(a, b) { | ||
for (var key in a) { | ||
if (key === 'children') { | ||
continue | ||
} | ||
if (a[key] !== b[key]) { | ||
return true | ||
} | ||
} | ||
for (var key$1 in b) { | ||
if (!(key$1 in a)) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
// Cross platform request animation frame | ||
var hasFrame = typeof requestAnimationFrame !== 'undefined'; | ||
var requestFrame = setTimeout; | ||
var cancelFrame = clearTimeout; | ||
/* istanbul ignore if */ | ||
if (hasFrame) { | ||
requestFrame = requestAnimationFrame; | ||
cancelFrame = cancelAnimationFrame; | ||
} | ||
/** | ||
* @fileoverview Presenter is a specialized React component that | ||
@@ -24,4 +62,4 @@ * creates a boundary between "smart" and "dumb" components. This | ||
presenter: this, | ||
parentState: this.state, | ||
parentProps: this.props | ||
presenterProps: this.props, | ||
presenterState: this.state | ||
}) | ||
@@ -51,2 +89,3 @@ } | ||
this.send = this.send.bind(this); | ||
this.state = {}; | ||
} | ||
@@ -58,26 +97,8 @@ | ||
Presenter.prototype._beginSetup = function _beginSetup (mediator ) { | ||
this.repo = mediator.repo; | ||
this.mediator = mediator; | ||
var prototypeAccessors = { model: {} }; | ||
this.setup(this.repo, this.props, this.state); | ||
this.model = this.mediator.updateModel(this.props, this.state); | ||
this.ready(this.repo, this.props, this.state); | ||
prototypeAccessors.model.get = function () { | ||
return this.mediator.model.value | ||
}; | ||
Presenter.prototype._beginTeardown = function _beginTeardown () { | ||
this.teardown(this.repo, this.props, this.state); | ||
}; | ||
Presenter.prototype._requestRepo = function _requestRepo (contextRepo ) { | ||
var givenRepo = this.props.repo || contextRepo; | ||
var workingRepo = this.getRepo(givenRepo, this.props); | ||
this.didFork = workingRepo !== givenRepo; | ||
return workingRepo | ||
}; | ||
/** | ||
@@ -100,2 +121,9 @@ * Called when a presenter is created, useful any prep work. `setup` | ||
Presenter.prototype.componentWillUpdate = function componentWillUpdate (props , state ) { | ||
if (shallowDiff(this.props, props) || shallowDiff(this.state, state)) { | ||
this._updateModel(props, state); | ||
this.update(this.repo, props, state); | ||
} | ||
}; | ||
/** | ||
@@ -125,10 +153,5 @@ * Called when a presenter gets new props. This is useful for secondary | ||
Presenter.prototype.intercept = function intercept () { | ||
return {} | ||
return null | ||
}; | ||
Presenter.prototype.componentWillUpdate = function componentWillUpdate (props , state ) { | ||
this.model = this.mediator.updateModel(props, state); | ||
this.update(this.repo, props, state); | ||
}; | ||
/** | ||
@@ -173,2 +196,34 @@ * Runs before assigning a repo to a Presenter. This method is given | ||
// Private | ||
Presenter.prototype._updateModel = function _updateModel (props , state ) { | ||
return this.mediator.model.bind(this.getModel(props, state)) | ||
}; | ||
Presenter.prototype._beginSetup = function _beginSetup (mediator ) { | ||
this.repo = mediator.repo; | ||
this.mediator = mediator; | ||
this.setup(this.repo, this.props, this.state); | ||
this._updateModel(this.props, this.state); | ||
this.ready(this.repo, this.props, this.state); | ||
}; | ||
Presenter.prototype._beginTeardown = function _beginTeardown () { | ||
this.teardown(this.repo, this.props, this.state); | ||
}; | ||
Presenter.prototype._requestRepo = function _requestRepo (contextRepo ) { | ||
var givenRepo = this.props.repo || contextRepo; | ||
var workingRepo = this.getRepo(givenRepo, this.props); | ||
this.didFork = workingRepo !== givenRepo; | ||
return workingRepo | ||
}; | ||
Object.defineProperties( Presenter.prototype, prototypeAccessors ); | ||
return Presenter; | ||
@@ -182,11 +237,10 @@ }(React.PureComponent)); | ||
this.presenter = props.presenter; | ||
this.repo = this.presenter._requestRepo(context.repo); | ||
this.send = this.send.bind(this); | ||
this._lastRevision = -Infinity; | ||
this.state = { repo: this.repo, send: this.send }; | ||
this.model = new Model(this.repo, this.presenter); | ||
this.model.on('change', this.updateState, this); | ||
// The following methods are autobound to protect scope | ||
this.send = this.send.bind(this); | ||
this._scheduleUpdate = this._scheduleUpdate.bind(this); | ||
} | ||
@@ -212,2 +266,3 @@ | ||
this.presenter.refs = this.refs; | ||
this.model.on('change', this._queueUpdate, this); | ||
}; | ||
@@ -225,14 +280,21 @@ | ||
this.presenter._beginTeardown(); | ||
this._stopUpdate(); | ||
}; | ||
PresenterMediator.prototype.render = function render () { | ||
// setObject might have been called before the model | ||
// can get assigned | ||
this.presenter.model = this.state; | ||
// Views can be getters, so pluck it out so that it is only evaluated once | ||
var view = this.presenter.view; | ||
var ref = this.presenter; | ||
var model = ref.model; | ||
var view = ref.view; | ||
var ref$1 = this.props; | ||
var presenterProps = ref$1.presenterProps; | ||
this._lastRevision = this.model.revision; | ||
if (view != null) { | ||
return React.createElement(view, merge(this.presenter.props, this.state)) | ||
return React.createElement( | ||
view, | ||
merge(presenterProps, { repo: this.repo, send: this.send }, model) | ||
) | ||
} | ||
@@ -243,26 +305,2 @@ | ||
PresenterMediator.prototype.updateState = function updateState (state ) { | ||
this.setState(state); | ||
}; | ||
PresenterMediator.prototype.updateModel = function updateModel (props , state ) { | ||
var bindings = this.presenter.getModel(props, state); | ||
this.model.bind(bindings); | ||
return this.model.value | ||
}; | ||
PresenterMediator.prototype.getParent = function getParent () { | ||
return this.context.parent | ||
}; | ||
PresenterMediator.prototype.getHandler = function getHandler (intent ) { | ||
var interceptors = this.presenter.intercept(); | ||
// A presenter's register goes through the same registration steps | ||
// Get the first index because Presenters can not chain | ||
return getRegistration(interceptors, intent, 'resolve')[0] | ||
}; | ||
PresenterMediator.prototype.send = function send (intent ) { | ||
@@ -276,3 +314,3 @@ var params = [], len = arguments.length - 1; | ||
while (mediator) { | ||
var handler = mediator.getHandler(taggedIntent); | ||
var handler = mediator._getHandler(taggedIntent); | ||
@@ -283,3 +321,3 @@ if (handler) { | ||
mediator = mediator.getParent(); | ||
mediator = mediator._getParent(); | ||
} | ||
@@ -292,2 +330,41 @@ | ||
// Private | ||
PresenterMediator.prototype._scheduleUpdate = function _scheduleUpdate () { | ||
if (this.model.revision > this._lastRevision) { | ||
this.forceUpdate(); | ||
} | ||
this._scheduledFrame = null; | ||
}; | ||
PresenterMediator.prototype._queueUpdate = function _queueUpdate () { | ||
if (this.repo.history.batch) { | ||
if (!this._scheduledFrame) { | ||
this._scheduledFrame = requestFrame(this._scheduleUpdate); | ||
} | ||
} else { | ||
this.forceUpdate(); | ||
} | ||
}; | ||
PresenterMediator.prototype._stopUpdate = function _stopUpdate () { | ||
if (this._scheduledFrame) { | ||
cancelFrame(this._scheduledFrame); | ||
this._scheduledFrame = null; | ||
} | ||
}; | ||
PresenterMediator.prototype._getParent = function _getParent () { | ||
return this.context.parent | ||
}; | ||
PresenterMediator.prototype._getHandler = function _getHandler (intent ) { | ||
var interceptors = this.presenter.intercept(); | ||
// A presenter's register goes through the same registration steps | ||
// Get the first index because Presenters can not chain | ||
return getRegistration(interceptors, intent, 'resolve')[0] | ||
}; | ||
return PresenterMediator; | ||
@@ -294,0 +371,0 @@ }(React.PureComponent)); |
@@ -854,2 +854,3 @@ /** | ||
this.setLimit(options.maxHistory); | ||
this.batch = options.batch; | ||
@@ -856,0 +857,0 @@ this.updater = options.updater(options); |
@@ -858,2 +858,3 @@ 'use strict'; | ||
this.setLimit(options.maxHistory); | ||
this.batch = options.batch; | ||
@@ -860,0 +861,0 @@ this.updater = options.updater(options); |
@@ -1,2 +0,2 @@ | ||
"use strict";function t(t){return t&&"function"==typeof t.subscribe}function i(t){return t&&"function"==typeof t.call}function s(t,s,o){return i(t)?t.call(o,s.state,s):t}var o=require("../microcosm.js"),n=function(i){function n(t,s){i.call(this),this.repo=t,this.scope=s,this.bindings={},this.subscriptions={},this.value={},this.repo.on("change",this.compute,this)}return i&&(n.__proto__=i),n.prototype=Object.create(i&&i.prototype),n.prototype.constructor=n,n.prototype.track=function(t,i){var s=this,o=this.subscriptions[t],n=i.subscribe(function(i){return s.set(t,i)});this.subscriptions[t]=n,o&&o.unsubscribe()},n.prototype.bind=function(i){var s=this;this.bindings={};for(var o in i){var n=i[o];t(n)?s.track(o,n):s.bindings[o]=n}this.compute()},n.prototype.set=function(t,i){var s=o.set(this.value,t,i);this.value!==s&&(this.value=s,this.t("change",this.value))},n.prototype.compute=function(){var t=this,i=this.value,n=i;for(var r in t.bindings){var e=s(t.bindings[r],t.repo,t.scope);n=o.set(n,r,e)}i!==n&&(this.value=n,this.t("change",n))},n.prototype.teardown=function(){var t=this;for(var i in t.subscriptions)t.subscriptions[i].unsubscribe();this.repo.off("change",this.compute,this)},n}(o.Emitter);module.exports=n; | ||
"use strict";function t(t){return t&&"function"==typeof t.subscribe}function i(t){return t&&"function"==typeof t.call}function s(t,s,r){return i(t)?t.call(r,s.state,s):t}var r=require("../microcosm.js"),n=function(i){function n(t,s){i.call(this),this.repo=t,this.scope=s,this.bindings={},this.subscriptions={},this.value={},this.revision=0,this.repo.on("change",this.compute,this)}return i&&(n.__proto__=i),n.prototype=Object.create(i&&i.prototype),n.prototype.constructor=n,n.prototype.track=function(t,i){var s=this,r=this.subscriptions[t],n=i.subscribe(function(i){return s.set(t,i)});this.subscriptions[t]=n,r&&r.unsubscribe()},n.prototype.bind=function(i){var s=this;this.bindings={};for(var r in i){var n=i[r];t(n)?s.track(r,n):s.bindings[r]=n}this.compute()},n.prototype.publish=function(t){return t!==this.value&&(this.value=t,this.revision+=1,this.t("change",this.value)),t},n.prototype.set=function(t,i){return this.publish(r.set(this.value,t,i))},n.prototype.compute=function(){var t=this,i=this.value;for(var n in t.bindings){var o=s(t.bindings[n],t.repo,t.scope);i=r.set(i,n,o)}return this.publish(i)},n.prototype.teardown=function(){var t=this;for(var i in t.subscriptions)t.subscriptions[i].unsubscribe();this.repo.off("change",this.compute,this)},n}(r.Emitter);module.exports=n; | ||
//# sourceMappingURL=model.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}function e(){return this.props.children?o.Children.only(this.props.children):null}function r(){return o.createElement(u,{presenter:this,parentState:this.state,parentProps:this.props})}var o=t(require("react")),n=require("../microcosm.js"),p=t(n),s=t(require("./model.js")),i=function(){},h=function(t){function o(o,n){t.call(this),this.render?this.defaultRender=this.render:this.defaultRender=e,this.render=r,this.send=this.send.bind(this)}return t&&(o.__proto__=t),o.prototype=Object.create(t&&t.prototype),o.prototype.constructor=o,o.prototype.e=function(t){this.repo=t.repo,this.mediator=t,this.setup(this.repo,this.props,this.state),this.model=this.mediator.updateModel(this.props,this.state),this.ready(this.repo,this.props,this.state)},o.prototype.r=function(){this.teardown(this.repo,this.props,this.state)},o.prototype.o=function(t){var e=this.props.repo||t,r=this.getRepo(e,this.props);return this.didFork=r!==e,r},o.prototype.setup=function(t,e,r){},o.prototype.ready=function(t,e,r){},o.prototype.update=function(t,e,r){},o.prototype.teardown=function(t,e,r){},o.prototype.intercept=function(){return{}},o.prototype.componentWillUpdate=function(t,e){this.model=this.mediator.updateModel(t,e),this.update(this.repo,t,e)},o.prototype.getRepo=function(t,e){return t?t.fork():new p},o.prototype.send=function(t){for(var e=[],r=arguments.length-1;r-- >0;)e[r]=arguments[r+1];return(o=this.mediator).send.apply(o,[t].concat(e));var o},o.prototype.getModel=function(t,e){return{}},o}(o.PureComponent),u=function(t){function e(e,r){t.call(this,e,r),this.presenter=e.presenter,this.repo=this.presenter.o(r.repo),this.send=this.send.bind(this),this.state={repo:this.repo,send:this.send},this.model=new s(this.repo,this.presenter),this.model.on("change",this.updateState,this)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getChildContext=function(){return{repo:this.repo,send:this.send,parent:this}},e.prototype.componentWillMount=function(){this.presenter.e(this)},e.prototype.componentDidMount=function(){this.presenter.refs=this.refs},e.prototype.componentWillUnmount=function(){this.presenter.refs=this.refs,this.presenter.didFork&&this.repo.shutdown(),this.model.teardown(),this.presenter.r()},e.prototype.render=function(){this.presenter.model=this.state;var t=this.presenter.view;return null!=t?o.createElement(t,n.merge(this.presenter.props,this.state)):this.presenter.defaultRender()},e.prototype.updateState=function(t){this.setState(t)},e.prototype.updateModel=function(t,e){var r=this.presenter.getModel(t,e);return this.model.bind(r),this.model.value},e.prototype.getParent=function(){return this.context.parent},e.prototype.getHandler=function(t){var e=this.presenter.intercept();return n.getRegistration(e,t,"resolve")[0]},e.prototype.send=function(t){for(var e=[],r=arguments.length-1;r-- >0;)e[r]=arguments[r+1];for(var o=n.tag(t),p=this;p;){var s=p.getHandler(o);if(s)return s.call.apply(s,[p.presenter,p.repo].concat(e));p=p.getParent()}return(i=this.repo).push.apply(i,arguments);var i},e}(o.PureComponent);u.contextTypes={repo:i,send:i,parent:i},u.childContextTypes={repo:i,send:i,parent:i},module.exports=h; | ||
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}function e(t,e){for(var r in t)if("children"!==r&&t[r]!==e[r])return!0;for(var o in e)if(!(o in t))return!0;return!1}function r(){return this.props.children?n.Children.only(this.props.children):null}function o(){return n.createElement(l,{presenter:this,presenterProps:this.props,presenterState:this.state})}var n=t(require("react")),i=require("../microcosm.js"),s=t(i),p=t(require("./model.js")),h="undefined"!=typeof requestAnimationFrame,u=setTimeout,d=clearTimeout;h&&(u=requestAnimationFrame,d=cancelAnimationFrame);var a=function(){},c=function(t){function n(e,n){t.call(this),this.render?this.defaultRender=this.render:this.defaultRender=r,this.render=o,this.send=this.send.bind(this),this.state={}}t&&(n.__proto__=t),n.prototype=Object.create(t&&t.prototype),n.prototype.constructor=n;var i={model:{}};return i.model.get=function(){return this.mediator.model.value},n.prototype.setup=function(t,e,r){},n.prototype.ready=function(t,e,r){},n.prototype.componentWillUpdate=function(t,r){(e(this.props,t)||e(this.state,r))&&(this.e(t,r),this.update(this.repo,t,r))},n.prototype.update=function(t,e,r){},n.prototype.teardown=function(t,e,r){},n.prototype.intercept=function(){return null},n.prototype.getRepo=function(t,e){return t?t.fork():new s},n.prototype.send=function(t){for(var e=[],r=arguments.length-1;r-- >0;)e[r]=arguments[r+1];return(o=this.mediator).send.apply(o,[t].concat(e));var o},n.prototype.getModel=function(t,e){return{}},n.prototype.e=function(t,e){return this.mediator.model.bind(this.getModel(t,e))},n.prototype.r=function(t){this.repo=t.repo,this.mediator=t,this.setup(this.repo,this.props,this.state),this.e(this.props,this.state),this.ready(this.repo,this.props,this.state)},n.prototype.o=function(){this.teardown(this.repo,this.props,this.state)},n.prototype.n=function(t){var e=this.props.repo||t,r=this.getRepo(e,this.props);return this.didFork=r!==e,r},Object.defineProperties(n.prototype,i),n}(n.PureComponent),l=function(t){function e(e,r){t.call(this,e,r),this.presenter=e.presenter,this.repo=this.presenter.n(r.repo),this.i=-1/0,this.model=new p(this.repo,this.presenter),this.send=this.send.bind(this),this.s=this.s.bind(this)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getChildContext=function(){return{repo:this.repo,send:this.send,parent:this}},e.prototype.componentWillMount=function(){this.presenter.r(this)},e.prototype.componentDidMount=function(){this.presenter.refs=this.refs,this.model.on("change",this.p,this)},e.prototype.componentWillUnmount=function(){this.presenter.refs=this.refs,this.presenter.didFork&&this.repo.shutdown(),this.model.teardown(),this.presenter.o(),this.h()},e.prototype.render=function(){var t=this.presenter,e=t.model,r=t.view,o=this.props.presenterProps;return this.i=this.model.revision,null!=r?n.createElement(r,i.merge(o,{repo:this.repo,send:this.send},e)):this.presenter.defaultRender()},e.prototype.send=function(t){for(var e=[],r=arguments.length-1;r-- >0;)e[r]=arguments[r+1];for(var o=i.tag(t),n=this;n;){var s=n.u(o);if(s)return s.call.apply(s,[n.presenter,n.repo].concat(e));n=n.d()}return(p=this.repo).push.apply(p,arguments);var p},e.prototype.s=function(){this.model.revision>this.i&&this.forceUpdate(),this.a=null},e.prototype.p=function(){this.repo.history.batch?this.a||(this.a=u(this.s)):this.forceUpdate()},e.prototype.h=function(){this.a&&(d(this.a),this.a=null)},e.prototype.d=function(){return this.context.parent},e.prototype.u=function(t){var e=this.presenter.intercept();return i.getRegistration(e,t,"resolve")[0]},e}(n.PureComponent);l.contextTypes={repo:a,send:a,parent:a},l.childContextTypes={repo:a,send:a,parent:a},module.exports=c; | ||
//# sourceMappingURL=presenter.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";function t(t){return Array.isArray(t)?t:f(t)?[]:"string"==typeof t?t.trim().split(j):[t]}function e(e){return"string"==typeof e?(""+e).split(k).map(t):e.every(Array.isArray)?e:e.map(t)}function n(t){return t.join(j)}function r(t){return t.map(n).join(k)}function i(t){return""+t+P++}function o(t,e){var n={};for(var r in e)r in t&&(n[r]=e[r]);return n}function s(t){if(Array.isArray(t))return t.slice(0);if(!1===c(t))return{};var e={};for(var n in t)e[n]=t[n];return e}function a(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];for(var n=null,r=null,i=0,o=t.length;i<o;i++)if(!1!==c(t[i])){n=n||t[i]||{},r=r||n;var a=t[i];for(var h in a)n[h]!==a[h]&&(n===r&&(n=s(r)),n[h]=a[h])}return n||{}}function h(e,n,r){for(var i=t(n),o=e,s=0,a=i.length;s<a&&null!=o;s++)o=o[i[s]];return void 0===o||null===o?arguments.length<=2?o:r:o}function p(e,n,r){var i=t(n),o=i.length;if(o<=0)return r;if(h(e,i)===r)return e;for(var a=s(e),p=a,u=0;u<o;u++){var c=i[u],l=r;u<o-1&&(l=c in p?s(p[c]):{}),p[c]=l,p=p[c]}return a}function u(t){return(c(t)||l(t))&&l(t.then)}function c(t){return!(!t||"object"!=typeof t)}function l(t){return!!t&&"function"==typeof t}function f(t){return""===t||null===t||void 0===t}function d(t){return t?t[D]||"":""}function y(t){return"GeneratorFunction"===d(t)}function v(t,e,n){return l(t)?new t(e,n):Object.create(t)}function g(e,n,r,i){var o=t(n);return!1===l(r)?p(e,o,r):p(e,o,r(h(e,o,i)))}function m(t,e){if("string"==typeof t)return m(function(t){return t},t);if(!0===t.i)return t;q+=1;var n=e||(t.name||H)+"."+q,r=t;return r.open=n+".open",r.loading=n+".loading",r.update=r.loading,r.done=n,r.resolve=r.done,r.error=n+".error",r.reject=r.error,r.cancel=n+".cancel",r.cancelled=t.cancel,r.toString=function(){return n},t.i=!0,r}function _(t){return function(e){!0===t.batch?N(e,T):e()}}function b(t,e){return function(n,r){var i=t;if(e)try{i=r.deserialize(t)}catch(t){throw n.reject(t),t}n.resolve(o(r.state,i))}}function x(t){return!Array.isArray(t)&&c(t)}function S(t,e,n){var r=[];if(null==t)return r;var i=V[n],o=t[e],s=e[n]||"";return r=x(o)?o[i]||o[n]:t[s],r?Array.isArray(r)?r:[r]:[]}function O(t,e,n,r){for(var i=n,o=0,s=t.length;o<s;o++)i=t[o].call(r,i,e);return i}function w(t,e,n){function r(e){var n=o.next(e);n.done?t.resolve(e):i(n.value)}function i(e){return Array.isArray(e)?i(n.parallel(e)):(e.onDone(r),e.onCancel(t.cancel,t),e.onError(t.reject,t),e)}t.open();var o=e(n);return r(),t}function A(t,e,n,r){if("string"==typeof e)return t.resolve.apply(t,n);var i=e.apply(null,n);return u(i)?(t.open.apply(t,n),i.then(function(e){return setTimeout(function(){return t.resolve(e)},0)},function(e){return setTimeout(function(){return t.reject(e)},0)}),t):y(i)?w(t,i,r):l(i)&&!n.some(function(t){return t===i})?(i(t,r),t):t.resolve(i)}function z(t){var e=("undefined"==typeof global?window:global)[et];e&&(e.emit("init",t),t.history.setLimit(1/0))}Object.defineProperty(exports,"__esModule",{value:!0});var j=".",k=",",I=l(Symbol)?Symbol:{},D=h(I,"toStringTag","@@toStringTag"),E=h(I,"iterator","@@iterator"),P=0,R=function(){this.o=[]};R.prototype.on=function(t,e,n){var r={event:t,fn:e,scope:n,once:!1};return this.o.push(r),this},R.prototype.once=function(t,e,n){var r={event:t,fn:e,scope:n,once:!0};return this.o.push(r),this},R.prototype.off=function(t,e,n){for(var r=this,i=null==e,o=0;o<this.o.length;){var s=r.o[o];s.event===t&&(i||s.fn===e&&s.scope===n)?r.o.splice(o,1):o+=1}return this},R.prototype.removeAllListeners=function(){this.o.length=0},R.prototype.t=function(t){for(var e=this,n=[],r=arguments.length-1;r-- >0;)n[r]=arguments[r+1];for(var i=0;i<this.o.length;){var o=e.o[i];o.event===t&&(o.fn.apply(o.scope||e,n),o.once)?e.o.splice(i,1):i+=1}return this},R.prototype.s=function(t){for(var e=this,n=0;n<this.o.length;)t!==e.o[n].scope?n+=1:e.o.splice(n,1)};var q=0,H="_action",L={inactive:!1,open:!1,update:!1,resolve:!0,reject:!0,cancel:!0},C=function(t){function e(e,n){t.call(this),this.id=i("action"),this.command=m(e),this.status="inactive",this.payload=void 0,this.disabled=!1,this.complete=!1,this.parent=null,this.next=null,this.timestamp=Date.now(),this.children=[],this.revisions=[],n&&this.setState(n)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var n={type:{},open:{},update:{},resolve:{},reject:{},cancel:{}};return n.type.get=function(){return this.command[this.status]||""},n.open.get=function(){return this.setState.bind(this,"open")},n.update.get=function(){return this.setState.bind(this,"update")},n.resolve.get=function(){return this.setState.bind(this,"resolve")},n.reject.get=function(){return this.setState.bind(this,"reject")},n.cancel.get=function(){return this.setState.bind(this,"cancel")},e.prototype.onOpen=function(t,e){return this.a("open",t,e),this},e.prototype.onUpdate=function(t,e){return t&&this.on("update",t,e),this},e.prototype.onDone=function(t,e){return this.a("resolve",t,e),this},e.prototype.onError=function(t,e){return this.a("reject",t,e),this},e.prototype.onCancel=function(t,e){return this.a("cancel",t,e),this},e.prototype.is=function(t){return this.command[this.status]===this.command[t]},e.prototype.toggle=function(t){return this.disabled=!this.disabled,t||this.t("change",this),this},e.prototype.link=function(t){var e=this,n=t.length,r=function(){n<=1?e.resolve():n-=1};return t.forEach(function(t){t.onDone(r),t.onCancel(r),t.onError(e.reject)}),r(),this},e.prototype.then=function(t,e){var n=this;return new Promise(function(t,e){n.onDone(t),n.onError(e)}).then(t,e)},e.prototype.isDisconnected=function(){return!this.parent},e.prototype.prune=function(){this.parent&&(this.parent.parent=null)},e.prototype.lead=function(t){this.next=t,t&&this.adopt(t)},e.prototype.adopt=function(t){this.children.indexOf(t)<0&&this.children.push(t),t.parent=this},e.prototype.remove=function(){this.parent&&this.parent.abandon(this),this.removeAllListeners()},e.prototype.abandon=function(t){var e=this.children.indexOf(t);e>=0&&(this.children.splice(e,1),t.parent=null),this.next===t&&this.lead(t.next)},e.prototype.a=function(t,e,n){e&&(this.is(t)?e.call(n,this.payload):this.once(t,e,n))},e.prototype.setState=function(t,e){return this.complete?this:(this.status=t,this.complete=L[t],arguments.length>1&&(this.payload=e),this.revisions.push({status:this.status,payload:this.payload,timestamp:Date.now()}),this.t("change",this),this.t(t,this.payload),this)},e.prototype.toString=function(){return this.command.toString()},e.prototype.toJSON=function(){return{id:this.id,status:this.status,type:this.type,payload:this.payload,disabled:this.disabled,children:this.children,revisions:this.revisions,next:this.next&&this.next.id}},Object.defineProperties(e.prototype,n),e}(R),N="undefined"!=typeof requestIdleCallback?requestIdleCallback:function(t){return setTimeout(t,4)},T={timeout:36},M=function(t,e){return b(t,e)},G=function(t,e){return b(t,e)},J=function(){},B=function(){},U=function(t){return t},Q={maxHistory:1,batch:!1,updater:_},F=function(t){function e(e){var n=this;t.call(this);var r=a(Q,e);this.size=0,this.setLimit(r.maxHistory),this.updater=r.updater(r),this.releasing=!1,this.release=function(){return n.closeRelease()},this.begin()}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.checkout=function(t){var e=this.sharedRoot(t);this.head=t||this.head;for(var n=this.head;n&&n!==e;){var r=n.parent;r&&r.lead(n),n=r}return this.setSize(),this.reconcile(e),this},e.prototype.toggle=function(t){var e=[].concat(t);e.forEach(function(t){return t.toggle(!0)});var n,r=1/0,i=this.toArray();e.forEach(function(t){var e=i.indexOf(t);e>=0&&e<r&&(r=e,n=t)}),n&&this.reconcile(n)},e.prototype.toArray=function(){return this.map(function(t){return t})},e.prototype[E]=function(){var t=this,e=this.root,n={next:function(){var r=e;return null==r?{done:!0}:(e=r==t.head?null:e.next,!r||r.command!==J&&r.command!==B&&r.command!==U?{value:r,done:!1}:n.next())}};return n},e.prototype.map=function(t,e){for(var n=this[E](),r=n.next(),i=[];!r.done;)i.push(t.call(e,r.value,i.length)),r=n.next();return i},e.prototype.wait=function(){var t=this,e=new C("GROUP");return e.link(this.toArray()),e.then(function(){if(t.releasing)return new Promise(function(e){t.once("release",e)})})},e.prototype.then=function(t,e){return this.wait().then(t,e)},e.prototype.begin=function(){this.root=this.head=this.append(B,"resolve")},e.prototype.append=function(t,e){var n=new C(t,e);return this.head?this.head.lead(n):(new C(J,"resolve").adopt(n),this.root=n),this.head=n,this.size+=1,n.on("change",this.reconcile,this),this.t("append",n),e&&n.command!==B&&this.reconcile(n),n},e.prototype.remove=function(t){if(!t.isDisconnected()){var e=t.parent,n=t.next,r=this.isActive(t);this.clean(t),this.size<=0?this.begin():(t===this.head&&e?n=this.head=e:t===this.root&&n&&(this.root=n),n&&r&&!t.disabled&&this.reconcile(n))}},e.prototype.clean=function(t){this.size-=1,this.t("remove",t),t.remove()},e.prototype.reconcile=function(t){for(var e=this,n=t;n&&(n.command!==B&&e.t("update",n),n!==e.head);)n=n.next;this.archive(),this.t("reconcile",t),this.queueRelease()},e.prototype.queueRelease=function(){!1===this.releasing&&(this.releasing=!0,this.updater(this.release))},e.prototype.closeRelease=function(){this.releasing=!1,this.t("release")},e.prototype.archive=function(){for(var t=this,e=this.size,n=this.root;e>this.limit&&n.complete;)e-=1,t.t("remove",n.parent),n.next&&(n=n.next);n!==this.root&&(this.root=n,n.prune()),this.size=e},e.prototype.setSize=function(){for(var t=this.head,e=1;t&&t!==this.root;)t=t.parent,e+=1;this.size=e},e.prototype.setLimit=function(t){this.limit=Math.max(Q.maxHistory,t)},e.prototype.isActive=function(t){for(var e=this,n=t;n;){if(n===e.head)return!0;n=n.next}return!1},e.prototype.sharedRoot=function(t){for(var e=this,n=t;n;){if(e.isActive(n))return n;n=n.parent}return this.head},e.prototype.toString=function(){return this.toArray().join(", ")},e.prototype.toJSON=function(){return{head:this.head.id,root:this.root.id,size:this.size,tree:this.root}},e}(R),K=function(){};K.prototype.setup=function(t){this.repo=t},K.prototype.reset=function(t,e){var n=o(t,e);return a(t,this.repo.getInitialState(),n)},K.prototype.patch=function(t,e){return a(t,o(t,e))},K.prototype.addDomain=function(t){return a(this.repo.getInitialState(),t)},K.prototype.register=function(){var t={};return t[M.toString()]=this.reset,t[G.toString()]=this.patch,t[U.toString()]=this.addDomain,t};var V={inactive:"inactive",open:"open",update:"loading",loading:"update",done:"resolve",resolve:"done",reject:"error",error:"reject",cancel:"cancelled",cancelled:"cancel"},W=function(t){this.repo=t,this.registry={},this.domains=[],this.add([],K)};W.prototype.getRepoHandlers=function(t){var e=t.command,n=t.status,r=S(this.repo.register(),e,n);return r.length?[{key:[],scope:this.repo,steps:r}]:[]},W.prototype.getHandlers=function(t){for(var e=this,n=this.getRepoHandlers(t),r=t.command,i=t.status,o=0;o<this.domains.length;o++){var s=e.domains[o],a=s[0],h=s[1];if(h.register){var p=S(h.register(),r,i);p.length&&n.push({key:a,scope:h,steps:p})}}return n},W.prototype.register=function(t){var e=t.type;return this.registry[e]||(this.registry[e]=this.getHandlers(t)),this.registry[e]},W.prototype.add=function(e,n,r){var i=a(this.repo.options,n.defaults,{key:e},r),o=v(n,i,this.repo),s=t(e);return this.domains.push([s,o]),this.registry={},o.setup&&o.setup(this.repo,i),o.teardown&&this.repo.on("teardown",o.teardown,o),o},W.prototype.dispatch=function(t,e,n){for(var r=this.register(t),i=e,o=0;o<r.length;o++){var s=r[o],a=s.key,u=s.scope,c=s.steps,l=h(i,a,null);i=l!==h(n.last,a,null)||t.payload!==n.payload||t.status!==n.status?p(i,a,O(c,t.payload,l,u)):p(i,a,h(n.next,a))}return i},W.prototype.deserialize=function(t){for(var e=this,n=t,r=0;r<this.domains.length;r++){var i=e.domains[r],o=i[0],s=i[1];s.deserialize&&(n=p(n,o,s.deserialize(h(t,o))))}return n},W.prototype.serialize=function(t,e){for(var n=this,r=e,i=0;i<this.domains.length;i++){var o=n.domains[i],s=o[0],a=o[1];a.serialize&&(r=p(r,s,a.serialize(h(t,s))))}return r};var X=function(t){this.repo=t,this.effects=[]};X.prototype.add=function(t,e){var n=a(this.repo.options,t.defaults,e),r=v(t,n,this.repo);return r.setup&&r.setup(this.repo,n),r.teardown&&this.repo.on("teardown",r.teardown,r),this.effects.push(r),r},X.prototype.dispatch=function(t){for(var e=this,n=t.command,r=t.payload,i=t.status,o=0;o<this.effects.length;o++){var s=e.effects[o];if(s.register)for(var a=S(s.register(),n,i),h=0;h<a.length;h++)a[h].call(s,e.repo,r)}};var Y=function(t,e,n){this.id=t,this.key=e,this.edges=[],this.parent=n||null,n&&n.connect(this)};Y.getId=function(t,e){return e&&e.id?e.id+"."+t:t},Y.prototype.connect=function(t){this.edges.push(t)},Y.prototype.disconnect=function(t){var e=this.edges.indexOf(t);~e&&this.edges.splice(e,1)},Y.prototype.isAlone=function(){return this.edges.length<=0},Y.prototype.orphan=function(){this.parent&&this.parent.disconnect(this)};var Z=function(t){function e(e,n){t.call(this),this.id=e,this.keyPaths=n}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.getId=function(t){return"query:"+r(t)},e.prototype.trigger=function(t){for(var e=this,n=["change"],r=0,i=this.keyPaths.length;r<i;r++)n[r+1]=h(t,e.keyPaths[r]);(o=this).t.apply(o,n);var o},e.prototype.isAlone=function(){return this.o.length<=0},e}(R),$="",tt=function(t){this.snapshot=t,this.nodes={},this.queries={}};tt.prototype.on=function(t,n,r){for(var i=this,o=e(t),s=this.addQuery(o),a=o.length-1;a>=0;a--)i.addBranch(o[a],s);return s.on("change",n,r),s},tt.prototype.off=function(t,n,r){var i=e(t),o=Z.getId(i),s=this.queries[o];s&&(s.off("change",n,r),s.isAlone()&&this.prune(s))},tt.prototype.update=function(t){var e=this.snapshot;if(this.snapshot=t,this.nodes[$])for(var n=this.scan(this.nodes[$],e,t,[]),r=0;r<n.length;r++)n[r].trigger(t)},tt.prototype.addNode=function(t,e){var n=Y.getId(t,e);return!1===this.nodes.hasOwnProperty(n)&&(this.nodes[n]=new Y(n,t,e)),this.nodes[n]},tt.prototype.addQuery=function(t){var e=Z.getId(t);return!1===this.queries.hasOwnProperty(e)&&(this.queries[e]=new Z(e,t)),this.queries[e]},tt.prototype.prune=function(t){for(var e=this,r=t.keyPaths.map(n),i=0,o=r.length;i<o;i++){var s=e.nodes[r[i]];s.disconnect(t);do{if(!s.isAlone())break;s.orphan(),delete e.nodes[s.id],s=s.parent}while(s)}delete this.queries[t.id]},tt.prototype.addBranch=function(t,e){for(var n=this,r=this.addNode($,null),i=0,o=t.length;i<o;i++)r=n.addNode(t[i],r);r.connect(e)},tt.prototype.scan=function(t,e,n,r){var i=this;if(e!==n)for(var o=t.edges,s=0,a=o.length;s<a;s++){var h=o[s];if(h instanceof Z&&r.indexOf(h)<0)r.push(h);else if(h instanceof Y){var p=null==e?e:e[h.key],u=null==n?n:n[h.key];i.scan(h,p,u,r)}}return r};var et="__MICROCOSM_DEVTOOLS_GLOBAL_HOOK__",nt={maxHistory:0,parent:null,batch:!1,debug:!1},rt=function(t){function e(e,n,r){t.call(this),this.options=a(nt,this.constructor.defaults,e||{}),this.parent=this.options.parent,this.initial=this.parent?this.parent.initial:this.getInitialState(),this.state=this.parent?this.parent.state:this.initial,this.history=this.parent?this.parent.history:new F(this.options),this.snapshots=Object.create(this.parent?this.parent.snapshots:null),this.domains=new W(this),this.effects=new X(this),this.changes=new tt(this.state),this.active=!0,this.history.on("append",this.createSnapshot,this),this.history.on("update",this.updateSnapshot,this),this.history.on("remove",this.removeSnapshot,this),this.history.on("reconcile",this.dispatchEffect,this),this.history.on("release",this.release,this),this.setup(this.options),n&&this.reset(n,r),this.options.debug&&z(this)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.setup=function(t){},e.prototype.teardown=function(){},e.prototype.getInitialState=function(){return null==this.initial?{}:this.initial},e.prototype.recall=function(t){return t&&t.id in this.snapshots?this.snapshots[t.id].next:this.getInitialState()},e.prototype.rebase=function(t){var e=this.recall(t.parent);return this.parent&&(e=a(e,this.parent.recall(t))),e},e.prototype.createSnapshot=function(t){var e={last:this.state,next:this.state,status:"inactive",payload:void 0};return this.snapshots[t.id]=e,e},e.prototype.updateSnapshot=function(t){var e=this.snapshots[t.id],n=this.rebase(t);t.disabled?e.next=n:e.next=this.domains.dispatch(t,n,e),this.snapshots[t.id]=a(e,{last:n,status:t.status,payload:t.payload}),this.state=e.next},e.prototype.removeSnapshot=function(t){delete this.snapshots[t.id]},e.prototype.dispatchEffect=function(t){this.effects.dispatch(t)},e.prototype.release=function(){this.changes.update(this.state)},e.prototype.on=function(e,n,r){var i=e.split(":",2),o=i[0],s=i[1];switch(o){case"change":this.changes.on(s||"",n,r);break;default:t.prototype.on.apply(this,arguments)}return this},e.prototype.off=function(e,n,r){var i=e.split(":",2),o=i[0],s=i[1];switch(o){case"change":this.changes.off(s||"",n,r);break;default:t.prototype.off.apply(this,arguments)}return this},e.prototype.append=function(t,e){return this.history.append(t,e)},e.prototype.push=function(t){for(var e=[],n=arguments.length-1;n-- >0;)e[n]=arguments[n+1];var r=this.append(t);return A(r,t,e,this),r},e.prototype.prepare=function(t){for(var e=this,n=[],r=arguments.length-1;r-- >0;)n[r]=arguments[r+1];return function(){for(var r=[],i=arguments.length;i--;)r[i]=arguments[i];return(o=e).push.apply(o,[t].concat(n,r));var o}},e.prototype.addDomain=function(t,e,n){var r=this.domains.add(t,e,n),i=r.getInitialState?r.getInitialState():null;return this.initial=p(this.initial,t,i),this.push(U,r),r},e.prototype.addEffect=function(t,e){return this.effects.add(t,e)},e.prototype.reset=function(t,e){return this.push(M,t,e)},e.prototype.patch=function(t,e){return this.push(G,t,e)},e.prototype.register=function(){return null},e.prototype.deserialize=function(t){var e=t;return this.parent?e=this.parent.deserialize(t):"string"==typeof e&&(e=JSON.parse(e)),this.domains.deserialize(e)},e.prototype.serialize=function(){var t=this.parent?this.parent.serialize():{};return this.domains.serialize(this.state,t)},e.prototype.toJSON=function(){return this.serialize()},e.prototype.checkout=function(t){return this.history.checkout(t),this},e.prototype.fork=function(){return new e({parent:this})},e.prototype.shutdown=function(){this.active=!1,this.teardown(),this.t("teardown",this),this.history.s(this),this.removeAllListeners()},e.prototype.parallel=function(t){return this.append("GROUP").link(t)},e}(R);exports.default=rt,exports.Microcosm=rt,exports.Action=C,exports.History=F,exports.Emitter=R,exports.tag=m,exports.get=h,exports.set=p,exports.update=g,exports.merge=a,exports.getRegistration=S; | ||
"use strict";function t(t){return Array.isArray(t)?t:f(t)?[]:"string"==typeof t?t.trim().split(j):[t]}function e(e){return"string"==typeof e?(""+e).split(k).map(t):e.every(Array.isArray)?e:e.map(t)}function n(t){return t.join(j)}function r(t){return t.map(n).join(k)}function i(t){return""+t+P++}function o(t,e){var n={};for(var r in e)r in t&&(n[r]=e[r]);return n}function s(t){if(Array.isArray(t))return t.slice(0);if(!1===c(t))return{};var e={};for(var n in t)e[n]=t[n];return e}function a(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];for(var n=null,r=null,i=0,o=t.length;i<o;i++)if(!1!==c(t[i])){n=n||t[i]||{},r=r||n;var a=t[i];for(var h in a)n[h]!==a[h]&&(n===r&&(n=s(r)),n[h]=a[h])}return n||{}}function h(e,n,r){for(var i=t(n),o=e,s=0,a=i.length;s<a&&null!=o;s++)o=o[i[s]];return void 0===o||null===o?arguments.length<=2?o:r:o}function p(e,n,r){var i=t(n),o=i.length;if(o<=0)return r;if(h(e,i)===r)return e;for(var a=s(e),p=a,u=0;u<o;u++){var c=i[u],l=r;u<o-1&&(l=c in p?s(p[c]):{}),p[c]=l,p=p[c]}return a}function u(t){return(c(t)||l(t))&&l(t.then)}function c(t){return!(!t||"object"!=typeof t)}function l(t){return!!t&&"function"==typeof t}function f(t){return""===t||null===t||void 0===t}function d(t){return t?t[D]||"":""}function y(t){return"GeneratorFunction"===d(t)}function v(t,e,n){return l(t)?new t(e,n):Object.create(t)}function g(e,n,r,i){var o=t(n);return!1===l(r)?p(e,o,r):p(e,o,r(h(e,o,i)))}function m(t,e){if("string"==typeof t)return m(function(t){return t},t);if(!0===t.l)return t;q+=1;var n=e||(t.name||H)+"."+q,r=t;return r.open=n+".open",r.loading=n+".loading",r.update=r.loading,r.done=n,r.resolve=r.done,r.error=n+".error",r.reject=r.error,r.cancel=n+".cancel",r.cancelled=t.cancel,r.toString=function(){return n},t.l=!0,r}function _(t){return function(e){!0===t.batch?N(e,T):e()}}function b(t,e){return function(n,r){var i=t;if(e)try{i=r.deserialize(t)}catch(t){throw n.reject(t),t}n.resolve(o(r.state,i))}}function x(t){return!Array.isArray(t)&&c(t)}function S(t,e,n){var r=[];if(null==t)return r;var i=V[n],o=t[e],s=e[n]||"";return r=x(o)?o[i]||o[n]:t[s],r?Array.isArray(r)?r:[r]:[]}function O(t,e,n,r){for(var i=n,o=0,s=t.length;o<s;o++)i=t[o].call(r,i,e);return i}function w(t,e,n){function r(e){var n=o.next(e);n.done?t.resolve(e):i(n.value)}function i(e){return Array.isArray(e)?i(n.parallel(e)):(e.onDone(r),e.onCancel(t.cancel,t),e.onError(t.reject,t),e)}t.open();var o=e(n);return r(),t}function A(t,e,n,r){if("string"==typeof e)return t.resolve.apply(t,n);var i=e.apply(null,n);return u(i)?(t.open.apply(t,n),i.then(function(e){return setTimeout(function(){return t.resolve(e)},0)},function(e){return setTimeout(function(){return t.reject(e)},0)}),t):y(i)?w(t,i,r):l(i)&&!n.some(function(t){return t===i})?(i(t,r),t):t.resolve(i)}function z(t){var e=("undefined"==typeof global?window:global)[et];e&&(e.emit("init",t),t.history.setLimit(1/0))}Object.defineProperty(exports,"__esModule",{value:!0});var j=".",k=",",I=l(Symbol)?Symbol:{},D=h(I,"toStringTag","@@toStringTag"),E=h(I,"iterator","@@iterator"),P=0,R=function(){this.f=[]};R.prototype.on=function(t,e,n){var r={event:t,fn:e,scope:n,once:!1};return this.f.push(r),this},R.prototype.once=function(t,e,n){var r={event:t,fn:e,scope:n,once:!0};return this.f.push(r),this},R.prototype.off=function(t,e,n){for(var r=this,i=null==e,o=0;o<this.f.length;){var s=r.f[o];s.event===t&&(i||s.fn===e&&s.scope===n)?r.f.splice(o,1):o+=1}return this},R.prototype.removeAllListeners=function(){this.f.length=0},R.prototype.t=function(t){for(var e=this,n=[],r=arguments.length-1;r-- >0;)n[r]=arguments[r+1];for(var i=0;i<this.f.length;){var o=e.f[i];o.event===t&&(o.fn.apply(o.scope||e,n),o.once)?e.f.splice(i,1):i+=1}return this},R.prototype.d=function(t){for(var e=this,n=0;n<this.f.length;)t!==e.f[n].scope?n+=1:e.f.splice(n,1)};var q=0,H="_action",L={inactive:!1,open:!1,update:!1,resolve:!0,reject:!0,cancel:!0},C=function(t){function e(e,n){t.call(this),this.id=i("action"),this.command=m(e),this.status="inactive",this.payload=void 0,this.disabled=!1,this.complete=!1,this.parent=null,this.next=null,this.timestamp=Date.now(),this.children=[],this.revisions=[],n&&this.setState(n)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var n={type:{},open:{},update:{},resolve:{},reject:{},cancel:{}};return n.type.get=function(){return this.command[this.status]||""},n.open.get=function(){return this.setState.bind(this,"open")},n.update.get=function(){return this.setState.bind(this,"update")},n.resolve.get=function(){return this.setState.bind(this,"resolve")},n.reject.get=function(){return this.setState.bind(this,"reject")},n.cancel.get=function(){return this.setState.bind(this,"cancel")},e.prototype.onOpen=function(t,e){return this.y("open",t,e),this},e.prototype.onUpdate=function(t,e){return t&&this.on("update",t,e),this},e.prototype.onDone=function(t,e){return this.y("resolve",t,e),this},e.prototype.onError=function(t,e){return this.y("reject",t,e),this},e.prototype.onCancel=function(t,e){return this.y("cancel",t,e),this},e.prototype.is=function(t){return this.command[this.status]===this.command[t]},e.prototype.toggle=function(t){return this.disabled=!this.disabled,t||this.t("change",this),this},e.prototype.link=function(t){var e=this,n=t.length,r=function(){n<=1?e.resolve():n-=1};return t.forEach(function(t){t.onDone(r),t.onCancel(r),t.onError(e.reject)}),r(),this},e.prototype.then=function(t,e){var n=this;return new Promise(function(t,e){n.onDone(t),n.onError(e)}).then(t,e)},e.prototype.isDisconnected=function(){return!this.parent},e.prototype.prune=function(){this.parent&&(this.parent.parent=null)},e.prototype.lead=function(t){this.next=t,t&&this.adopt(t)},e.prototype.adopt=function(t){this.children.indexOf(t)<0&&this.children.push(t),t.parent=this},e.prototype.remove=function(){this.parent&&this.parent.abandon(this),this.removeAllListeners()},e.prototype.abandon=function(t){var e=this.children.indexOf(t);e>=0&&(this.children.splice(e,1),t.parent=null),this.next===t&&this.lead(t.next)},e.prototype.y=function(t,e,n){e&&(this.is(t)?e.call(n,this.payload):this.once(t,e,n))},e.prototype.setState=function(t,e){return this.complete?this:(this.status=t,this.complete=L[t],arguments.length>1&&(this.payload=e),this.revisions.push({status:this.status,payload:this.payload,timestamp:Date.now()}),this.t("change",this),this.t(t,this.payload),this)},e.prototype.toString=function(){return this.command.toString()},e.prototype.toJSON=function(){return{id:this.id,status:this.status,type:this.type,payload:this.payload,disabled:this.disabled,children:this.children,revisions:this.revisions,next:this.next&&this.next.id}},Object.defineProperties(e.prototype,n),e}(R),N="undefined"!=typeof requestIdleCallback?requestIdleCallback:function(t){return setTimeout(t,4)},T={timeout:36},M=function(t,e){return b(t,e)},G=function(t,e){return b(t,e)},J=function(){},B=function(){},U=function(t){return t},Q={maxHistory:1,batch:!1,updater:_},F=function(t){function e(e){var n=this;t.call(this);var r=a(Q,e);this.size=0,this.setLimit(r.maxHistory),this.batch=r.batch,this.updater=r.updater(r),this.releasing=!1,this.release=function(){return n.closeRelease()},this.begin()}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.checkout=function(t){var e=this.sharedRoot(t);this.head=t||this.head;for(var n=this.head;n&&n!==e;){var r=n.parent;r&&r.lead(n),n=r}return this.setSize(),this.reconcile(e),this},e.prototype.toggle=function(t){var e=[].concat(t);e.forEach(function(t){return t.toggle(!0)});var n,r=1/0,i=this.toArray();e.forEach(function(t){var e=i.indexOf(t);e>=0&&e<r&&(r=e,n=t)}),n&&this.reconcile(n)},e.prototype.toArray=function(){return this.map(function(t){return t})},e.prototype[E]=function(){var t=this,e=this.root,n={next:function(){var r=e;return null==r?{done:!0}:(e=r==t.head?null:e.next,!r||r.command!==J&&r.command!==B&&r.command!==U?{value:r,done:!1}:n.next())}};return n},e.prototype.map=function(t,e){for(var n=this[E](),r=n.next(),i=[];!r.done;)i.push(t.call(e,r.value,i.length)),r=n.next();return i},e.prototype.wait=function(){var t=this,e=new C("GROUP");return e.link(this.toArray()),e.then(function(){if(t.releasing)return new Promise(function(e){t.once("release",e)})})},e.prototype.then=function(t,e){return this.wait().then(t,e)},e.prototype.begin=function(){this.root=this.head=this.append(B,"resolve")},e.prototype.append=function(t,e){var n=new C(t,e);return this.head?this.head.lead(n):(new C(J,"resolve").adopt(n),this.root=n),this.head=n,this.size+=1,n.on("change",this.reconcile,this),this.t("append",n),e&&n.command!==B&&this.reconcile(n),n},e.prototype.remove=function(t){if(!t.isDisconnected()){var e=t.parent,n=t.next,r=this.isActive(t);this.clean(t),this.size<=0?this.begin():(t===this.head&&e?n=this.head=e:t===this.root&&n&&(this.root=n),n&&r&&!t.disabled&&this.reconcile(n))}},e.prototype.clean=function(t){this.size-=1,this.t("remove",t),t.remove()},e.prototype.reconcile=function(t){for(var e=this,n=t;n&&(n.command!==B&&e.t("update",n),n!==e.head);)n=n.next;this.archive(),this.t("reconcile",t),this.queueRelease()},e.prototype.queueRelease=function(){!1===this.releasing&&(this.releasing=!0,this.updater(this.release))},e.prototype.closeRelease=function(){this.releasing=!1,this.t("release")},e.prototype.archive=function(){for(var t=this,e=this.size,n=this.root;e>this.limit&&n.complete;)e-=1,t.t("remove",n.parent),n.next&&(n=n.next);n!==this.root&&(this.root=n,n.prune()),this.size=e},e.prototype.setSize=function(){for(var t=this.head,e=1;t&&t!==this.root;)t=t.parent,e+=1;this.size=e},e.prototype.setLimit=function(t){this.limit=Math.max(Q.maxHistory,t)},e.prototype.isActive=function(t){for(var e=this,n=t;n;){if(n===e.head)return!0;n=n.next}return!1},e.prototype.sharedRoot=function(t){for(var e=this,n=t;n;){if(e.isActive(n))return n;n=n.parent}return this.head},e.prototype.toString=function(){return this.toArray().join(", ")},e.prototype.toJSON=function(){return{head:this.head.id,root:this.root.id,size:this.size,tree:this.root}},e}(R),K=function(){};K.prototype.setup=function(t){this.repo=t},K.prototype.reset=function(t,e){var n=o(t,e);return a(t,this.repo.getInitialState(),n)},K.prototype.patch=function(t,e){return a(t,o(t,e))},K.prototype.addDomain=function(t){return a(this.repo.getInitialState(),t)},K.prototype.register=function(){var t={};return t[M.toString()]=this.reset,t[G.toString()]=this.patch,t[U.toString()]=this.addDomain,t};var V={inactive:"inactive",open:"open",update:"loading",loading:"update",done:"resolve",resolve:"done",reject:"error",error:"reject",cancel:"cancelled",cancelled:"cancel"},W=function(t){this.repo=t,this.registry={},this.domains=[],this.add([],K)};W.prototype.getRepoHandlers=function(t){var e=t.command,n=t.status,r=S(this.repo.register(),e,n);return r.length?[{key:[],scope:this.repo,steps:r}]:[]},W.prototype.getHandlers=function(t){for(var e=this,n=this.getRepoHandlers(t),r=t.command,i=t.status,o=0;o<this.domains.length;o++){var s=e.domains[o],a=s[0],h=s[1];if(h.register){var p=S(h.register(),r,i);p.length&&n.push({key:a,scope:h,steps:p})}}return n},W.prototype.register=function(t){var e=t.type;return this.registry[e]||(this.registry[e]=this.getHandlers(t)),this.registry[e]},W.prototype.add=function(e,n,r){var i=a(this.repo.options,n.defaults,{key:e},r),o=v(n,i,this.repo),s=t(e);return this.domains.push([s,o]),this.registry={},o.setup&&o.setup(this.repo,i),o.teardown&&this.repo.on("teardown",o.teardown,o),o},W.prototype.dispatch=function(t,e,n){for(var r=this.register(t),i=e,o=0;o<r.length;o++){var s=r[o],a=s.key,u=s.scope,c=s.steps,l=h(i,a,null);i=l!==h(n.last,a,null)||t.payload!==n.payload||t.status!==n.status?p(i,a,O(c,t.payload,l,u)):p(i,a,h(n.next,a))}return i},W.prototype.deserialize=function(t){for(var e=this,n=t,r=0;r<this.domains.length;r++){var i=e.domains[r],o=i[0],s=i[1];s.deserialize&&(n=p(n,o,s.deserialize(h(t,o))))}return n},W.prototype.serialize=function(t,e){for(var n=this,r=e,i=0;i<this.domains.length;i++){var o=n.domains[i],s=o[0],a=o[1];a.serialize&&(r=p(r,s,a.serialize(h(t,s))))}return r};var X=function(t){this.repo=t,this.effects=[]};X.prototype.add=function(t,e){var n=a(this.repo.options,t.defaults,e),r=v(t,n,this.repo);return r.setup&&r.setup(this.repo,n),r.teardown&&this.repo.on("teardown",r.teardown,r),this.effects.push(r),r},X.prototype.dispatch=function(t){for(var e=this,n=t.command,r=t.payload,i=t.status,o=0;o<this.effects.length;o++){var s=e.effects[o];if(s.register)for(var a=S(s.register(),n,i),h=0;h<a.length;h++)a[h].call(s,e.repo,r)}};var Y=function(t,e,n){this.id=t,this.key=e,this.edges=[],this.parent=n||null,n&&n.connect(this)};Y.getId=function(t,e){return e&&e.id?e.id+"."+t:t},Y.prototype.connect=function(t){this.edges.push(t)},Y.prototype.disconnect=function(t){var e=this.edges.indexOf(t);~e&&this.edges.splice(e,1)},Y.prototype.isAlone=function(){return this.edges.length<=0},Y.prototype.orphan=function(){this.parent&&this.parent.disconnect(this)};var Z=function(t){function e(e,n){t.call(this),this.id=e,this.keyPaths=n}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.getId=function(t){return"query:"+r(t)},e.prototype.trigger=function(t){for(var e=this,n=["change"],r=0,i=this.keyPaths.length;r<i;r++)n[r+1]=h(t,e.keyPaths[r]);(o=this).t.apply(o,n);var o},e.prototype.isAlone=function(){return this.f.length<=0},e}(R),$="",tt=function(t){this.snapshot=t,this.nodes={},this.queries={}};tt.prototype.on=function(t,n,r){for(var i=this,o=e(t),s=this.addQuery(o),a=o.length-1;a>=0;a--)i.addBranch(o[a],s);return s.on("change",n,r),s},tt.prototype.off=function(t,n,r){var i=e(t),o=Z.getId(i),s=this.queries[o];s&&(s.off("change",n,r),s.isAlone()&&this.prune(s))},tt.prototype.update=function(t){var e=this.snapshot;if(this.snapshot=t,this.nodes[$])for(var n=this.scan(this.nodes[$],e,t,[]),r=0;r<n.length;r++)n[r].trigger(t)},tt.prototype.addNode=function(t,e){var n=Y.getId(t,e);return!1===this.nodes.hasOwnProperty(n)&&(this.nodes[n]=new Y(n,t,e)),this.nodes[n]},tt.prototype.addQuery=function(t){var e=Z.getId(t);return!1===this.queries.hasOwnProperty(e)&&(this.queries[e]=new Z(e,t)),this.queries[e]},tt.prototype.prune=function(t){for(var e=this,r=t.keyPaths.map(n),i=0,o=r.length;i<o;i++){var s=e.nodes[r[i]];s.disconnect(t);do{if(!s.isAlone())break;s.orphan(),delete e.nodes[s.id],s=s.parent}while(s)}delete this.queries[t.id]},tt.prototype.addBranch=function(t,e){for(var n=this,r=this.addNode($,null),i=0,o=t.length;i<o;i++)r=n.addNode(t[i],r);r.connect(e)},tt.prototype.scan=function(t,e,n,r){var i=this;if(e!==n)for(var o=t.edges,s=0,a=o.length;s<a;s++){var h=o[s];if(h instanceof Z&&r.indexOf(h)<0)r.push(h);else if(h instanceof Y){var p=null==e?e:e[h.key],u=null==n?n:n[h.key];i.scan(h,p,u,r)}}return r};var et="__MICROCOSM_DEVTOOLS_GLOBAL_HOOK__",nt={maxHistory:0,parent:null,batch:!1,debug:!1},rt=function(t){function e(e,n,r){t.call(this),this.options=a(nt,this.constructor.defaults,e||{}),this.parent=this.options.parent,this.initial=this.parent?this.parent.initial:this.getInitialState(),this.state=this.parent?this.parent.state:this.initial,this.history=this.parent?this.parent.history:new F(this.options),this.snapshots=Object.create(this.parent?this.parent.snapshots:null),this.domains=new W(this),this.effects=new X(this),this.changes=new tt(this.state),this.active=!0,this.history.on("append",this.createSnapshot,this),this.history.on("update",this.updateSnapshot,this),this.history.on("remove",this.removeSnapshot,this),this.history.on("reconcile",this.dispatchEffect,this),this.history.on("release",this.release,this),this.setup(this.options),n&&this.reset(n,r),this.options.debug&&z(this)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.setup=function(t){},e.prototype.teardown=function(){},e.prototype.getInitialState=function(){return null==this.initial?{}:this.initial},e.prototype.recall=function(t){return t&&t.id in this.snapshots?this.snapshots[t.id].next:this.getInitialState()},e.prototype.rebase=function(t){var e=this.recall(t.parent);return this.parent&&(e=a(e,this.parent.recall(t))),e},e.prototype.createSnapshot=function(t){var e={last:this.state,next:this.state,status:"inactive",payload:void 0};return this.snapshots[t.id]=e,e},e.prototype.updateSnapshot=function(t){var e=this.snapshots[t.id],n=this.rebase(t);t.disabled?e.next=n:e.next=this.domains.dispatch(t,n,e),this.snapshots[t.id]=a(e,{last:n,status:t.status,payload:t.payload}),this.state=e.next},e.prototype.removeSnapshot=function(t){delete this.snapshots[t.id]},e.prototype.dispatchEffect=function(t){this.effects.dispatch(t)},e.prototype.release=function(){this.changes.update(this.state)},e.prototype.on=function(e,n,r){var i=e.split(":",2),o=i[0],s=i[1];switch(o){case"change":this.changes.on(s||"",n,r);break;default:t.prototype.on.apply(this,arguments)}return this},e.prototype.off=function(e,n,r){var i=e.split(":",2),o=i[0],s=i[1];switch(o){case"change":this.changes.off(s||"",n,r);break;default:t.prototype.off.apply(this,arguments)}return this},e.prototype.append=function(t,e){return this.history.append(t,e)},e.prototype.push=function(t){for(var e=[],n=arguments.length-1;n-- >0;)e[n]=arguments[n+1];var r=this.append(t);return A(r,t,e,this),r},e.prototype.prepare=function(t){for(var e=this,n=[],r=arguments.length-1;r-- >0;)n[r]=arguments[r+1];return function(){for(var r=[],i=arguments.length;i--;)r[i]=arguments[i];return(o=e).push.apply(o,[t].concat(n,r));var o}},e.prototype.addDomain=function(t,e,n){var r=this.domains.add(t,e,n),i=r.getInitialState?r.getInitialState():null;return this.initial=p(this.initial,t,i),this.push(U,r),r},e.prototype.addEffect=function(t,e){return this.effects.add(t,e)},e.prototype.reset=function(t,e){return this.push(M,t,e)},e.prototype.patch=function(t,e){return this.push(G,t,e)},e.prototype.register=function(){return null},e.prototype.deserialize=function(t){var e=t;return this.parent?e=this.parent.deserialize(t):"string"==typeof e&&(e=JSON.parse(e)),this.domains.deserialize(e)},e.prototype.serialize=function(){var t=this.parent?this.parent.serialize():{};return this.domains.serialize(this.state,t)},e.prototype.toJSON=function(){return this.serialize()},e.prototype.checkout=function(t){return this.history.checkout(t),this},e.prototype.fork=function(){return new e({parent:this})},e.prototype.shutdown=function(){this.active=!1,this.teardown(),this.t("teardown",this),this.history.d(this),this.removeAllListeners()},e.prototype.parallel=function(t){return this.append("GROUP").link(t)},e}(R);exports.default=rt,exports.Microcosm=rt,exports.Action=C,exports.History=F,exports.Emitter=R,exports.tag=m,exports.get=h,exports.set=p,exports.update=g,exports.merge=a,exports.getRegistration=S; | ||
//# sourceMappingURL=microcosm.js.map |
{ | ||
"name": "microcosm", | ||
"version": "12.12.0", | ||
"version": "12.13.0-alpha.0", | ||
"description": "Flux with actions at center stage. Write optimistic updates, cancel requests, and track changes with ease.", | ||
@@ -5,0 +5,0 @@ "main": "microcosm.js", |
@@ -36,2 +36,3 @@ 'use strict'; | ||
this.value = {}; | ||
this.revision = 0; | ||
@@ -79,2 +80,12 @@ this.repo.on('change', this.compute, this); | ||
Model.prototype.publish = function publish (value ) { | ||
if (value !== this.value) { | ||
this.value = value; | ||
this.revision += 1; | ||
this._emit('change', this.value); | ||
} | ||
return value | ||
}; | ||
/** | ||
@@ -84,8 +95,3 @@ * Update a specific model key. Emits a change event | ||
Model.prototype.set = function set$1 (key , value ) { | ||
var next = ___microcosm_js.set(this.value, key, value); | ||
if (this.value !== next) { | ||
this.value = next; | ||
this._emit('change', this.value); | ||
} | ||
return this.publish(___microcosm_js.set(this.value, key, value)) | ||
}; | ||
@@ -102,2 +108,3 @@ | ||
var next = last; | ||
for (var key in this$1.bindings) { | ||
@@ -109,6 +116,3 @@ var value = invoke(this$1.bindings[key], this$1.repo, this$1.scope); | ||
if (last !== next) { | ||
this.value = next; | ||
this._emit('change', next); | ||
} | ||
return this.publish(next) | ||
}; | ||
@@ -115,0 +119,0 @@ |
@@ -11,2 +11,40 @@ 'use strict'; | ||
/** | ||
* Diffing algorithm for presenters. We need to recalculate the | ||
* model of props are state change, but ignore children. | ||
*/ | ||
function shallowDiff(a, b) { | ||
for (var key in a) { | ||
if (key === 'children') { | ||
continue | ||
} | ||
if (a[key] !== b[key]) { | ||
return true | ||
} | ||
} | ||
for (var key$1 in b) { | ||
if (!(key$1 in a)) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
// Cross platform request animation frame | ||
var hasFrame = typeof requestAnimationFrame !== 'undefined'; | ||
var requestFrame = setTimeout; | ||
var cancelFrame = clearTimeout; | ||
/* istanbul ignore if */ | ||
if (hasFrame) { | ||
requestFrame = requestAnimationFrame; | ||
cancelFrame = cancelAnimationFrame; | ||
} | ||
/** | ||
* @fileoverview Presenter is a specialized React component that | ||
@@ -29,4 +67,4 @@ * creates a boundary between "smart" and "dumb" components. This | ||
presenter: this, | ||
parentState: this.state, | ||
parentProps: this.props | ||
presenterProps: this.props, | ||
presenterState: this.state | ||
}) | ||
@@ -56,2 +94,3 @@ } | ||
this.send = this.send.bind(this); | ||
this.state = {}; | ||
} | ||
@@ -63,26 +102,8 @@ | ||
Presenter.prototype._beginSetup = function _beginSetup (mediator ) { | ||
this.repo = mediator.repo; | ||
this.mediator = mediator; | ||
var prototypeAccessors = { model: {} }; | ||
this.setup(this.repo, this.props, this.state); | ||
this.model = this.mediator.updateModel(this.props, this.state); | ||
this.ready(this.repo, this.props, this.state); | ||
prototypeAccessors.model.get = function () { | ||
return this.mediator.model.value | ||
}; | ||
Presenter.prototype._beginTeardown = function _beginTeardown () { | ||
this.teardown(this.repo, this.props, this.state); | ||
}; | ||
Presenter.prototype._requestRepo = function _requestRepo (contextRepo ) { | ||
var givenRepo = this.props.repo || contextRepo; | ||
var workingRepo = this.getRepo(givenRepo, this.props); | ||
this.didFork = workingRepo !== givenRepo; | ||
return workingRepo | ||
}; | ||
/** | ||
@@ -105,2 +126,9 @@ * Called when a presenter is created, useful any prep work. `setup` | ||
Presenter.prototype.componentWillUpdate = function componentWillUpdate (props , state ) { | ||
if (shallowDiff(this.props, props) || shallowDiff(this.state, state)) { | ||
this._updateModel(props, state); | ||
this.update(this.repo, props, state); | ||
} | ||
}; | ||
/** | ||
@@ -130,10 +158,5 @@ * Called when a presenter gets new props. This is useful for secondary | ||
Presenter.prototype.intercept = function intercept () { | ||
return {} | ||
return null | ||
}; | ||
Presenter.prototype.componentWillUpdate = function componentWillUpdate (props , state ) { | ||
this.model = this.mediator.updateModel(props, state); | ||
this.update(this.repo, props, state); | ||
}; | ||
/** | ||
@@ -178,2 +201,34 @@ * Runs before assigning a repo to a Presenter. This method is given | ||
// Private | ||
Presenter.prototype._updateModel = function _updateModel (props , state ) { | ||
return this.mediator.model.bind(this.getModel(props, state)) | ||
}; | ||
Presenter.prototype._beginSetup = function _beginSetup (mediator ) { | ||
this.repo = mediator.repo; | ||
this.mediator = mediator; | ||
this.setup(this.repo, this.props, this.state); | ||
this._updateModel(this.props, this.state); | ||
this.ready(this.repo, this.props, this.state); | ||
}; | ||
Presenter.prototype._beginTeardown = function _beginTeardown () { | ||
this.teardown(this.repo, this.props, this.state); | ||
}; | ||
Presenter.prototype._requestRepo = function _requestRepo (contextRepo ) { | ||
var givenRepo = this.props.repo || contextRepo; | ||
var workingRepo = this.getRepo(givenRepo, this.props); | ||
this.didFork = workingRepo !== givenRepo; | ||
return workingRepo | ||
}; | ||
Object.defineProperties( Presenter.prototype, prototypeAccessors ); | ||
return Presenter; | ||
@@ -187,11 +242,10 @@ }(React.PureComponent)); | ||
this.presenter = props.presenter; | ||
this.repo = this.presenter._requestRepo(context.repo); | ||
this.send = this.send.bind(this); | ||
this._lastRevision = -Infinity; | ||
this.state = { repo: this.repo, send: this.send }; | ||
this.model = new Model(this.repo, this.presenter); | ||
this.model.on('change', this.updateState, this); | ||
// The following methods are autobound to protect scope | ||
this.send = this.send.bind(this); | ||
this._scheduleUpdate = this._scheduleUpdate.bind(this); | ||
} | ||
@@ -217,2 +271,3 @@ | ||
this.presenter.refs = this.refs; | ||
this.model.on('change', this._queueUpdate, this); | ||
}; | ||
@@ -230,14 +285,21 @@ | ||
this.presenter._beginTeardown(); | ||
this._stopUpdate(); | ||
}; | ||
PresenterMediator.prototype.render = function render () { | ||
// setObject might have been called before the model | ||
// can get assigned | ||
this.presenter.model = this.state; | ||
// Views can be getters, so pluck it out so that it is only evaluated once | ||
var view = this.presenter.view; | ||
var ref = this.presenter; | ||
var model = ref.model; | ||
var view = ref.view; | ||
var ref$1 = this.props; | ||
var presenterProps = ref$1.presenterProps; | ||
this._lastRevision = this.model.revision; | ||
if (view != null) { | ||
return React.createElement(view, Microcosm.merge(this.presenter.props, this.state)) | ||
return React.createElement( | ||
view, | ||
Microcosm.merge(presenterProps, { repo: this.repo, send: this.send }, model) | ||
) | ||
} | ||
@@ -248,26 +310,2 @@ | ||
PresenterMediator.prototype.updateState = function updateState (state ) { | ||
this.setState(state); | ||
}; | ||
PresenterMediator.prototype.updateModel = function updateModel (props , state ) { | ||
var bindings = this.presenter.getModel(props, state); | ||
this.model.bind(bindings); | ||
return this.model.value | ||
}; | ||
PresenterMediator.prototype.getParent = function getParent () { | ||
return this.context.parent | ||
}; | ||
PresenterMediator.prototype.getHandler = function getHandler (intent ) { | ||
var interceptors = this.presenter.intercept(); | ||
// A presenter's register goes through the same registration steps | ||
// Get the first index because Presenters can not chain | ||
return Microcosm.getRegistration(interceptors, intent, 'resolve')[0] | ||
}; | ||
PresenterMediator.prototype.send = function send (intent ) { | ||
@@ -281,3 +319,3 @@ var params = [], len = arguments.length - 1; | ||
while (mediator) { | ||
var handler = mediator.getHandler(taggedIntent); | ||
var handler = mediator._getHandler(taggedIntent); | ||
@@ -288,3 +326,3 @@ if (handler) { | ||
mediator = mediator.getParent(); | ||
mediator = mediator._getParent(); | ||
} | ||
@@ -297,2 +335,41 @@ | ||
// Private | ||
PresenterMediator.prototype._scheduleUpdate = function _scheduleUpdate () { | ||
if (this.model.revision > this._lastRevision) { | ||
this.forceUpdate(); | ||
} | ||
this._scheduledFrame = null; | ||
}; | ||
PresenterMediator.prototype._queueUpdate = function _queueUpdate () { | ||
if (this.repo.history.batch) { | ||
if (!this._scheduledFrame) { | ||
this._scheduledFrame = requestFrame(this._scheduleUpdate); | ||
} | ||
} else { | ||
this.forceUpdate(); | ||
} | ||
}; | ||
PresenterMediator.prototype._stopUpdate = function _stopUpdate () { | ||
if (this._scheduledFrame) { | ||
cancelFrame(this._scheduledFrame); | ||
this._scheduledFrame = null; | ||
} | ||
}; | ||
PresenterMediator.prototype._getParent = function _getParent () { | ||
return this.context.parent | ||
}; | ||
PresenterMediator.prototype._getHandler = function _getHandler (intent ) { | ||
var interceptors = this.presenter.intercept(); | ||
// A presenter's register goes through the same registration steps | ||
// Get the first index because Presenters can not chain | ||
return Microcosm.getRegistration(interceptors, intent, 'resolve')[0] | ||
}; | ||
return PresenterMediator; | ||
@@ -299,0 +376,0 @@ }(React.PureComponent)); |
@@ -888,2 +888,3 @@ 'use strict'; | ||
this.setLimit(options.maxHistory); | ||
this.batch = options.batch; | ||
@@ -890,0 +891,0 @@ this.updater = options.updater(options); |
{ | ||
"name": "microcosm", | ||
"version": "12.12.0", | ||
"version": "12.13.0-alpha.0", | ||
"description": "Flux with actions at center stage. Write optimistic updates, cancel requests, and track changes with ease.", | ||
@@ -5,0 +5,0 @@ "main": "microcosm.js", |
@@ -38,2 +38,3 @@ (function (global, factory) { | ||
this.value = {}; | ||
this.revision = 0; | ||
@@ -81,2 +82,12 @@ this.repo.on('change', this.compute, this); | ||
Model.prototype.publish = function publish (value ) { | ||
if (value !== this.value) { | ||
this.value = value; | ||
this.revision += 1; | ||
this._emit('change', this.value); | ||
} | ||
return value | ||
}; | ||
/** | ||
@@ -86,8 +97,3 @@ * Update a specific model key. Emits a change event | ||
Model.prototype.set = function set$1 (key , value ) { | ||
var next = ___microcosm_js.set(this.value, key, value); | ||
if (this.value !== next) { | ||
this.value = next; | ||
this._emit('change', this.value); | ||
} | ||
return this.publish(___microcosm_js.set(this.value, key, value)) | ||
}; | ||
@@ -104,2 +110,3 @@ | ||
var next = last; | ||
for (var key in this$1.bindings) { | ||
@@ -111,6 +118,3 @@ var value = invoke(this$1.bindings[key], this$1.repo, this$1.scope); | ||
if (last !== next) { | ||
this.value = next; | ||
this._emit('change', next); | ||
} | ||
return this.publish(next) | ||
}; | ||
@@ -117,0 +121,0 @@ |
@@ -12,2 +12,40 @@ (function (global, factory) { | ||
/** | ||
* Diffing algorithm for presenters. We need to recalculate the | ||
* model of props are state change, but ignore children. | ||
*/ | ||
function shallowDiff(a, b) { | ||
for (var key in a) { | ||
if (key === 'children') { | ||
continue | ||
} | ||
if (a[key] !== b[key]) { | ||
return true | ||
} | ||
} | ||
for (var key$1 in b) { | ||
if (!(key$1 in a)) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
// Cross platform request animation frame | ||
var hasFrame = typeof requestAnimationFrame !== 'undefined'; | ||
var requestFrame = setTimeout; | ||
var cancelFrame = clearTimeout; | ||
/* istanbul ignore if */ | ||
if (hasFrame) { | ||
requestFrame = requestAnimationFrame; | ||
cancelFrame = cancelAnimationFrame; | ||
} | ||
/** | ||
* @fileoverview Presenter is a specialized React component that | ||
@@ -30,4 +68,4 @@ * creates a boundary between "smart" and "dumb" components. This | ||
presenter: this, | ||
parentState: this.state, | ||
parentProps: this.props | ||
presenterProps: this.props, | ||
presenterState: this.state | ||
}) | ||
@@ -57,2 +95,3 @@ } | ||
this.send = this.send.bind(this); | ||
this.state = {}; | ||
} | ||
@@ -64,26 +103,8 @@ | ||
Presenter.prototype._beginSetup = function _beginSetup (mediator ) { | ||
this.repo = mediator.repo; | ||
this.mediator = mediator; | ||
var prototypeAccessors = { model: {} }; | ||
this.setup(this.repo, this.props, this.state); | ||
this.model = this.mediator.updateModel(this.props, this.state); | ||
this.ready(this.repo, this.props, this.state); | ||
prototypeAccessors.model.get = function () { | ||
return this.mediator.model.value | ||
}; | ||
Presenter.prototype._beginTeardown = function _beginTeardown () { | ||
this.teardown(this.repo, this.props, this.state); | ||
}; | ||
Presenter.prototype._requestRepo = function _requestRepo (contextRepo ) { | ||
var givenRepo = this.props.repo || contextRepo; | ||
var workingRepo = this.getRepo(givenRepo, this.props); | ||
this.didFork = workingRepo !== givenRepo; | ||
return workingRepo | ||
}; | ||
/** | ||
@@ -106,2 +127,9 @@ * Called when a presenter is created, useful any prep work. `setup` | ||
Presenter.prototype.componentWillUpdate = function componentWillUpdate (props , state ) { | ||
if (shallowDiff(this.props, props) || shallowDiff(this.state, state)) { | ||
this._updateModel(props, state); | ||
this.update(this.repo, props, state); | ||
} | ||
}; | ||
/** | ||
@@ -131,10 +159,5 @@ * Called when a presenter gets new props. This is useful for secondary | ||
Presenter.prototype.intercept = function intercept () { | ||
return {} | ||
return null | ||
}; | ||
Presenter.prototype.componentWillUpdate = function componentWillUpdate (props , state ) { | ||
this.model = this.mediator.updateModel(props, state); | ||
this.update(this.repo, props, state); | ||
}; | ||
/** | ||
@@ -179,2 +202,34 @@ * Runs before assigning a repo to a Presenter. This method is given | ||
// Private | ||
Presenter.prototype._updateModel = function _updateModel (props , state ) { | ||
return this.mediator.model.bind(this.getModel(props, state)) | ||
}; | ||
Presenter.prototype._beginSetup = function _beginSetup (mediator ) { | ||
this.repo = mediator.repo; | ||
this.mediator = mediator; | ||
this.setup(this.repo, this.props, this.state); | ||
this._updateModel(this.props, this.state); | ||
this.ready(this.repo, this.props, this.state); | ||
}; | ||
Presenter.prototype._beginTeardown = function _beginTeardown () { | ||
this.teardown(this.repo, this.props, this.state); | ||
}; | ||
Presenter.prototype._requestRepo = function _requestRepo (contextRepo ) { | ||
var givenRepo = this.props.repo || contextRepo; | ||
var workingRepo = this.getRepo(givenRepo, this.props); | ||
this.didFork = workingRepo !== givenRepo; | ||
return workingRepo | ||
}; | ||
Object.defineProperties( Presenter.prototype, prototypeAccessors ); | ||
return Presenter; | ||
@@ -188,11 +243,10 @@ }(React.PureComponent)); | ||
this.presenter = props.presenter; | ||
this.repo = this.presenter._requestRepo(context.repo); | ||
this.send = this.send.bind(this); | ||
this._lastRevision = -Infinity; | ||
this.state = { repo: this.repo, send: this.send }; | ||
this.model = new Model(this.repo, this.presenter); | ||
this.model.on('change', this.updateState, this); | ||
// The following methods are autobound to protect scope | ||
this.send = this.send.bind(this); | ||
this._scheduleUpdate = this._scheduleUpdate.bind(this); | ||
} | ||
@@ -218,2 +272,3 @@ | ||
this.presenter.refs = this.refs; | ||
this.model.on('change', this._queueUpdate, this); | ||
}; | ||
@@ -231,14 +286,21 @@ | ||
this.presenter._beginTeardown(); | ||
this._stopUpdate(); | ||
}; | ||
PresenterMediator.prototype.render = function render () { | ||
// setObject might have been called before the model | ||
// can get assigned | ||
this.presenter.model = this.state; | ||
// Views can be getters, so pluck it out so that it is only evaluated once | ||
var view = this.presenter.view; | ||
var ref = this.presenter; | ||
var model = ref.model; | ||
var view = ref.view; | ||
var ref$1 = this.props; | ||
var presenterProps = ref$1.presenterProps; | ||
this._lastRevision = this.model.revision; | ||
if (view != null) { | ||
return React.createElement(view, Microcosm.merge(this.presenter.props, this.state)) | ||
return React.createElement( | ||
view, | ||
Microcosm.merge(presenterProps, { repo: this.repo, send: this.send }, model) | ||
) | ||
} | ||
@@ -249,26 +311,2 @@ | ||
PresenterMediator.prototype.updateState = function updateState (state ) { | ||
this.setState(state); | ||
}; | ||
PresenterMediator.prototype.updateModel = function updateModel (props , state ) { | ||
var bindings = this.presenter.getModel(props, state); | ||
this.model.bind(bindings); | ||
return this.model.value | ||
}; | ||
PresenterMediator.prototype.getParent = function getParent () { | ||
return this.context.parent | ||
}; | ||
PresenterMediator.prototype.getHandler = function getHandler (intent ) { | ||
var interceptors = this.presenter.intercept(); | ||
// A presenter's register goes through the same registration steps | ||
// Get the first index because Presenters can not chain | ||
return Microcosm.getRegistration(interceptors, intent, 'resolve')[0] | ||
}; | ||
PresenterMediator.prototype.send = function send (intent ) { | ||
@@ -282,3 +320,3 @@ var params = [], len = arguments.length - 1; | ||
while (mediator) { | ||
var handler = mediator.getHandler(taggedIntent); | ||
var handler = mediator._getHandler(taggedIntent); | ||
@@ -289,3 +327,3 @@ if (handler) { | ||
mediator = mediator.getParent(); | ||
mediator = mediator._getParent(); | ||
} | ||
@@ -298,2 +336,41 @@ | ||
// Private | ||
PresenterMediator.prototype._scheduleUpdate = function _scheduleUpdate () { | ||
if (this.model.revision > this._lastRevision) { | ||
this.forceUpdate(); | ||
} | ||
this._scheduledFrame = null; | ||
}; | ||
PresenterMediator.prototype._queueUpdate = function _queueUpdate () { | ||
if (this.repo.history.batch) { | ||
if (!this._scheduledFrame) { | ||
this._scheduledFrame = requestFrame(this._scheduleUpdate); | ||
} | ||
} else { | ||
this.forceUpdate(); | ||
} | ||
}; | ||
PresenterMediator.prototype._stopUpdate = function _stopUpdate () { | ||
if (this._scheduledFrame) { | ||
cancelFrame(this._scheduledFrame); | ||
this._scheduledFrame = null; | ||
} | ||
}; | ||
PresenterMediator.prototype._getParent = function _getParent () { | ||
return this.context.parent | ||
}; | ||
PresenterMediator.prototype._getHandler = function _getHandler (intent ) { | ||
var interceptors = this.presenter.intercept(); | ||
// A presenter's register goes through the same registration steps | ||
// Get the first index because Presenters can not chain | ||
return Microcosm.getRegistration(interceptors, intent, 'resolve')[0] | ||
}; | ||
return PresenterMediator; | ||
@@ -300,0 +377,0 @@ }(React.PureComponent)); |
@@ -860,2 +860,3 @@ (function (global, factory) { | ||
this.setLimit(options.maxHistory); | ||
this.batch = options.batch; | ||
@@ -862,0 +863,0 @@ this.updater = options.updater(options); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
416189
11405
7