New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

microcosm

Package Overview
Dependencies
Maintainers
4
Versions
233
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

microcosm - npm Package Compare versions

Comparing version 11.5.1 to 11.6.0-rc.0

addons/intent-button.js

47

addons/form.js

@@ -8,31 +8,25 @@ 'use strict';

var react = require('react');
var ___microcosm_js = require('../microcosm.js');
var serialize = _interopDefault(require('form-serialize'));
var ___microcosm_js = require('../microcosm.js');
var Form = react.createClass({
function Form () {
react.Component.apply(this, arguments);
contextTypes: {
send : react.PropTypes.func.isRequired
},
this.send = this.props.send || this.context.send;
this.onSubmit = this.onSubmit.bind(this);
}
propTypes: {
intent : react.PropTypes.oneOfType([ react.PropTypes.string, react.PropTypes.func]),
serializer : react.PropTypes.func,
prepare : react.PropTypes.func,
onSubmit : react.PropTypes.func,
onDone : react.PropTypes.func,
onUpdate : react.PropTypes.func,
onError : react.PropTypes.func,
onCancel : react.PropTypes.func
},
Form.contextTypes = {
send : react.PropTypes.func
};
getDefaultProps: function getDefaultProps() {
return {
intent : null,
serializer : function (form) { return serialize(form, { hash: true, empty: true }); },
prepare : function (n) { return n; },
onSubmit : function () {}
}
},
Form.defaultProps = {
intent : null,
serializer : function (form) { return serialize(form, { hash: true, empty: true }); },
prepare : function (n) { return n; },
onSubmit : function (n) { return n; }
};
___microcosm_js.inherit(Form, react.Component, {
render: function render() {

@@ -49,2 +43,3 @@ var props = ___microcosm_js.merge({}, this.props, { ref: 'form', onSubmit: this.onSubmit });

delete props.onError;
delete props.send;

@@ -54,3 +49,3 @@ return react.createElement('form', props)

onSubmit: function onSubmit(event) {
onSubmit: function onSubmit (event) {
event.preventDefault();

@@ -60,6 +55,6 @@ this.submit(event);

submit: function submit(event) {
submit: function submit (event) {
var form = this.refs.form;
var params = this.props.prepare(this.props.serializer(form));
var action = this.context.send(this.props.intent, params);
var action = this.send(this.props.intent, params);

@@ -66,0 +61,0 @@ if (action && action instanceof ___microcosm_js.Action) {

@@ -1,1 +0,1 @@

"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var r=require("react"),n=e(require("form-serialize")),t=require("../microcosm.js"),o=r.createClass({contextTypes:{send:r.PropTypes.func.isRequired},propTypes:{intent:r.PropTypes.oneOfType([r.PropTypes.string,r.PropTypes.func]),serializer:r.PropTypes.func,prepare:r.PropTypes.func,onSubmit:r.PropTypes.func,onDone:r.PropTypes.func,onUpdate:r.PropTypes.func,onError:r.PropTypes.func,onCancel:r.PropTypes.func},getDefaultProps:function(){return{intent:null,serializer:function(e){return n(e,{hash:!0,empty:!0})},prepare:function(e){return e},onSubmit:function(){}}},render:function(){var e=t.merge({},this.props,{ref:"form",onSubmit:this.onSubmit});return delete e.intent,delete e.prepare,delete e.serializer,delete e.onDone,delete e.onUpdate,delete e.onCancel,delete e.onError,r.createElement("form",e)},onSubmit:function(e){e.preventDefault(),this.submit(e)},submit:function(e){var r=this.refs.form,n=this.props.prepare(this.props.serializer(r)),o=this.context.send(this.props.intent,n);o&&o instanceof t.Action&&o.onDone(this.props.onDone).onUpdate(this.props.onUpdate).onCancel(this.props.onCancel).onError(this.props.onError),this.props.onSubmit(e,o)}});exports.default=o;
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}function t(){n.Component.apply(this,arguments),this.send=this.props.send||this.context.send,this.onSubmit=this.onSubmit.bind(this)}Object.defineProperty(exports,"__esModule",{value:!0});var n=require("react"),r=require("../microcosm.js"),o=e(require("form-serialize"));t.contextTypes={send:n.PropTypes.func},t.defaultProps={intent:null,serializer:function(e){return o(e,{hash:!0,empty:!0})},prepare:function(e){return e},onSubmit:function(e){return e}},r.inherit(t,n.Component,{render:function(){var e=r.merge({},this.props,{ref:"form",onSubmit:this.onSubmit});return delete e.intent,delete e.prepare,delete e.serializer,delete e.onDone,delete e.onUpdate,delete e.onCancel,delete e.onError,delete e.send,n.createElement("form",e)},onSubmit:function(e){e.preventDefault(),this.submit(e)},submit:function(e){var t=this.refs.form,n=this.props.prepare(this.props.serializer(t)),o=this.send(this.props.intent,n);o&&o instanceof r.Action&&o.onDone(this.props.onDone).onUpdate(this.props.onUpdate).onCancel(this.props.onCancel).onError(this.props.onError),this.props.onSubmit(e,o)}}),exports.default=t;

@@ -271,10 +271,11 @@ 'use strict';

if (this.context.send) {
return (ref$2 = this.context).send.apply(ref$2, [ intent ].concat( params ))
// Do not allow transfer across repos
if (Microcosm.get(this.repo, 'history') === Microcosm.get(this.context, ['repo', 'history'])) {
return this.context.send.apply(null, arguments)
}
}
// If we hit the top, push the intent into the Microcosm instance
return (ref$3 = this.repo).push.apply(ref$3, [ intent ].concat( params ))
return this.repo.push.apply(this.repo, arguments)
var ref$1;
var ref$2;
var ref$3;
}

@@ -281,0 +282,0 @@ });

@@ -1,1 +0,1 @@

"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}function t(e,r){i.apply(this,arguments),this.view===t.prototype.view&&this.render!==t.prototype.render&&(this.view=this.render.bind(this),this.render=t.prototype.render.bind(this))}function r(e,t){i.apply(this,arguments),this.repo=this.getRepo(),this.state={},this.send=this.send.bind(this),e.presenter._connectSend(this.send)}Object.defineProperty(exports,"__esModule",{value:!0});var p=require("react"),n=require("../microcosm.js"),o=e(n),s={},i=p.PureComponent||p.Component;n.inherit(t,i,{getRepo:function(e,t){return e?e.fork():new o},_setRepo:function(e){this.repo=e,this.setup(e,this.props,this.props.state)},_connectSend:function(e){this.send=e},setup:function(e,t,r){},update:function(e,t,r){},componentWillUpdate:function(e,t){this.update(this.repo,e,t)},teardown:function(e,t,r){},register:function(){},model:function(e,t,r){return s},view:function(e){return this.props.children?p.Children.only(this.props.children):null},render:function(){return p.createElement(r,{parentProps:this.props,parentState:this.state,presenter:this,view:this.view,repo:this.props.repo})}}),n.inherit(r,i,{getChildContext:function(){return{repo:this.repo,send:this.send}},componentWillMount:function(){this.props.presenter._setRepo(this.repo),this.recalculate(this.props)},componentDidMount:function(){this.repo.on("change",this.updateState,this),this.props.presenter.refs=this.refs},componentDidUpdate:function(){this.props.presenter.refs=this.refs},componentWillUnmount:function(){var e=this.props,t=e.presenter,r=e.parentProps,p=e.parentState,n=e.repo;t.teardown(this.repo,r,p),this.repo!==(n||this.context.repo)&&this.repo.teardown()},componentWillReceiveProps:function(e){this.recalculate(e)},render:function(){var e=this.props,t=e.presenter,r=e.parentProps,o=n.merge(r,{send:this.send,repo:this.repo},this.state);return t.hasOwnProperty("view")||t.view.prototype.isReactComponent?p.createElement(t.view,o):t.view(o)},getRepo:function(){var e=this.props,t=e.presenter,r=e.parentProps,p=e.repo;return t.getRepo(p||this.context.repo,r)},updatePropMap:function(e){var t=e.presenter,r=e.parentProps,p=e.parentState;this.propMap=t.model(r,p,this.repo),this.propMapKeys=Object.keys(this.propMap||s)},recalculate:function(e){this.updatePropMap(e),this.updateState()},updateState:function(){var e=this.getState();e&&this.setState(e)},getState:function(){var e=this,t=this.repo.state;if("function"==typeof this.propMap)return this.propMap(t);for(var r=null,p=this.propMapKeys.length-1;p>=0;--p){var n=e.propMapKeys[p],o=e.propMap[n],s="function"==typeof o?o(t):o;e.state[n]!==s&&(r=r||{},r[n]=s)}return r},send:function(e){for(var t=[],r=arguments.length-1;r-- >0;)t[r]=arguments[r+1];var p=this.props,o=p.presenter,s=o.register();return e=n.tag(e),s&&s.hasOwnProperty(e)?(i=s[e]).call.apply(i,[o,this.repo].concat(t)):this.context.send?(h=this.context).send.apply(h,[e].concat(t)):(a=this.repo).push.apply(a,[e].concat(t));var i,h,a}}),r.propTypes={repo:p.PropTypes.object},r.contextTypes={repo:p.PropTypes.object,send:p.PropTypes.func},r.childContextTypes={repo:p.PropTypes.object,send:p.PropTypes.func},exports.default=t;
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}function t(e,r){i.apply(this,arguments),this.view===t.prototype.view&&this.render!==t.prototype.render&&(this.view=this.render.bind(this),this.render=t.prototype.render.bind(this))}function r(e,t){i.apply(this,arguments),this.repo=this.getRepo(),this.state={},this.send=this.send.bind(this),e.presenter._connectSend(this.send)}Object.defineProperty(exports,"__esModule",{value:!0});var p=require("react"),n=require("../microcosm.js"),o=e(n),s={},i=p.PureComponent||p.Component;n.inherit(t,i,{getRepo:function(e,t){return e?e.fork():new o},_setRepo:function(e){this.repo=e,this.setup(e,this.props,this.props.state)},_connectSend:function(e){this.send=e},setup:function(e,t,r){},update:function(e,t,r){},componentWillUpdate:function(e,t){this.update(this.repo,e,t)},teardown:function(e,t,r){},register:function(){},model:function(e,t,r){return s},view:function(e){return this.props.children?p.Children.only(this.props.children):null},render:function(){return p.createElement(r,{parentProps:this.props,parentState:this.state,presenter:this,view:this.view,repo:this.props.repo})}}),n.inherit(r,i,{getChildContext:function(){return{repo:this.repo,send:this.send}},componentWillMount:function(){this.props.presenter._setRepo(this.repo),this.recalculate(this.props)},componentDidMount:function(){this.repo.on("change",this.updateState,this),this.props.presenter.refs=this.refs},componentDidUpdate:function(){this.props.presenter.refs=this.refs},componentWillUnmount:function(){var e=this.props,t=e.presenter,r=e.parentProps,p=e.parentState,n=e.repo;t.teardown(this.repo,r,p),this.repo!==(n||this.context.repo)&&this.repo.teardown()},componentWillReceiveProps:function(e){this.recalculate(e)},render:function(){var e=this.props,t=e.presenter,r=e.parentProps,o=n.merge(r,{send:this.send,repo:this.repo},this.state);return t.hasOwnProperty("view")||t.view.prototype.isReactComponent?p.createElement(t.view,o):t.view(o)},getRepo:function(){var e=this.props,t=e.presenter,r=e.parentProps,p=e.repo;return t.getRepo(p||this.context.repo,r)},updatePropMap:function(e){var t=e.presenter,r=e.parentProps,p=e.parentState;this.propMap=t.model(r,p,this.repo),this.propMapKeys=Object.keys(this.propMap||s)},recalculate:function(e){this.updatePropMap(e),this.updateState()},updateState:function(){var e=this.getState();e&&this.setState(e)},getState:function(){var e=this,t=this.repo.state;if("function"==typeof this.propMap)return this.propMap(t);for(var r=null,p=this.propMapKeys.length-1;p>=0;--p){var n=e.propMapKeys[p],o=e.propMap[n],s="function"==typeof o?o(t):o;e.state[n]!==s&&(r=r||{},r[n]=s)}return r},send:function(e){for(var t=[],r=arguments.length-1;r-- >0;)t[r]=arguments[r+1];var p=this.props,o=p.presenter,s=o.register();return e=n.tag(e),s&&s.hasOwnProperty(e)?(i=s[e]).call.apply(i,[o,this.repo].concat(t)):this.context.send&&n.get(this.repo,"history")===n.get(this.context,["repo","history"])?this.context.send.apply(null,arguments):this.repo.push.apply(this.repo,arguments);var i}}),r.propTypes={repo:p.PropTypes.object},r.contextTypes={repo:p.PropTypes.object,send:p.PropTypes.func},r.childContextTypes={repo:p.PropTypes.object,send:p.PropTypes.func},exports.default=t;
# Changelog
## 11.6.0
- Added deprecation warning for `action.send()`. Future versions of
Microcosm will use `action.update()`. This is more consistent with
other nomenclature.
- Added `update` alias for action `loading` status
- Added `resolve` alias for action `done` status
- Added `reject` alias for action `error` status
- Added `cancel` alias for action `cancelled` status
- `Form` addon now inherits from `React.Component` instead of using
`createClass`.
- Added `IntentButton` addon. This is similar to the `Form`.
- Fix bug where intents would bubble up across repos with different
histories.
### Upgrading
This should be a pretty simple upgrade. Just replace calls to
`action.send()` with `action.update()`.
## 11.5.1

@@ -4,0 +24,0 @@

@@ -172,5 +172,5 @@ # Actions

action.open()
setTimeout(() => action.send(25), 500)
setTimeout(() => action.send(50), 1000)
setTimeout(() => action.send(75), 1500)
setTimeout(() => action.update(25), 500)
setTimeout(() => action.update(50), 1000)
setTimeout(() => action.update(75), 1500)
setTimeout(() => action.resolve(100), 1000)

@@ -212,3 +212,3 @@ }

### `send([payload])`
### `update([payload])`

@@ -215,0 +215,0 @@ Send a progress update. This will move an action into the `loading`

@@ -18,3 +18,4 @@ ## Introduction

2. [Form](api/form.md)
3. [withIntent](api/with-intent.md)
3. [IntentButton](api/intent-button.md)
4. [withIntent](api/with-intent.md)

@@ -21,0 +22,0 @@ ## Testing

@@ -140,7 +140,15 @@ 'use strict';

fn.open = symbol + '.open';
fn.loading = symbol + '.loading';
fn.done = symbol; // intentional
fn.error = symbol + '.error';
fn.open = symbol + '.open';
fn.loading = symbol + '.loading';
fn.update = fn.loading;
fn.done = symbol; // intentional
fn.resolve = fn.done;
fn.error = symbol + '.error';
fn.reject = fn.error;
fn.cancelled = symbol + '.cancelled';
fn.cancel = fn.cancelled;

@@ -593,3 +601,3 @@ // The default state is done

*/
send: function send (payload) {
update: function update (payload) {
if (!this.disposable) {

@@ -610,2 +618,12 @@ this.type = this.behavior.loading;

send: function send () {
if (typeof console !== 'undefined') {
console.warn('`send` was deprecated in 11.6.0.',
'Please use `update` instead.',
'`send` will be removed in 12.0.0.');
}
return this.update.apply(this, arguments)
},
/**

@@ -612,0 +630,0 @@ * Set the action state to "error" and marks the action for clean up, then

@@ -1,1 +0,1 @@

"use strict";function t(){this._events=null}function e(t,e){if(null==t)throw new Error("Unable to identify "+t+" action");if(t.done)return t;"string"==typeof t&&(e=t,t=function(t){return t}),x+=1;var i=e||(t.name||z)+"."+x;return t.open=i+".open",t.loading=i+".loading",t.done=i,t.error=i+".error",t.cancelled=i+".cancelled",t.toString=k,t}function i(t){void 0===t&&(t=0),this.repos=[],this.limit=t}function n(t){if(Array.isArray(t))return t.slice(0);var e={};for(var i in t)e[i]=t[i];return e}function r(t){for(var e=arguments,i=t,r=1,s=arguments.length;r<s;r++){var h=e[r];for(var o in h)i[o]!==h[o]&&(i===t&&(i=n(t)),i[o]=h[o])}return i}function s(t,e,i){return t.__proto__=e,t.prototype=r(Object.create(e.prototype),{constructor:t},i),t}function h(t,e,i){return null==t?i:null==e?t:Array.isArray(e)?o(t,e,i):j.call(t,e)?t[e]:i}function o(t,e,i){for(var n=t,r=0,s=e.length;r<s;r++)n=h(n,e[r],i);return n}function a(t,e,i){if(Array.isArray(e))return u(t,e,i);if(null==e)return i;if(void 0===i||h(t,e)===i)return t;var r=n(t);return r[e]=i,r}function u(t,e,i){if(o(t,e)===i)return t;var r=e[0],s=e.slice(1),h=n(t);return s.length?h[r]=r in h?u(h[r],s,i):u({},s,i):h[r]=i,h}function l(t){return t.split(/\./)}function c(t){var e=t.split(/\s*\,\s*/);return e.map(l)}function f(t,e,i){return e.reduce(function(e,i){return a(e,i,h(t,i))},i||{})}function p(n,r){t.call(this),this.behavior=e(n),this.history=r||new i}function d(){this.reset=function(t,e){return function(i,n){var s=n.getInitialState(),h=t;e&&(h=n.deserialize(t)),i.resolve(r(s,h))}},this.patch=function(t,e){return function(i,n){var r=t;e&&(r=n.deserialize(r)),i.resolve(r)}},this.rebase=function(t){return t}}function v(t,e){for(var i=[],n=null!=S[e],r=0,s=t.length;r<s;r++){var h=t[r],o=h[0],a=h[1],u=null;n&&null!=a[e]?u=a[e]:null!=a.register&&(u=a.register()[e]),u&&i.push({key:o,domain:a,handler:u,length:u.length})}return i}function y(t){this.repo=t,this.domains=[],this.registry={},this.meta=this.add(null,d)}function g(t,e){return function(i){var n=e.register()[i.type];n&&n.call(e,t,i.payload)}}function m(t,e,i){var n=null;n="function"==typeof e?new e(t,i):Object.create(e),n.setup&&n.setup(t,i),n.register&&t.on("effect",g(t,n)),n.teardown&&t.on("teardown",n.teardown,n)}function b(t,e){return!!t&&("object"===e||"function"===e)&&"function"==typeof t.then}function w(t,e,i){var n=typeof e;return b(e,n)?(t.open(),e.then(function(e){return global.setTimeout(function(){return t.resolve(e)},0)},function(e){return global.setTimeout(function(){return t.reject(e)},0)}),t):"function"===n?(e(t,i),t):t.resolve(e)}function _(e,n,r){t.call(this),e=e||{},this.parent=e.parent||null,this.history=this.parent?this.parent.history:new i(e.maxHistory),this.history.addRepo(this),this.realm=new y(this),this.archived=this.parent?this.parent.archived:{},this.cached=this.parent?this.parent.cached:this.archived,this.staged=this.parent?this.parent.state:this.cached,this.state=this.parent?this.parent.state:this.staged,this.follower=!!this.parent,this.indexes={},this.dirty=!1,this.setup(e),n&&this.reset(n,r)}Object.defineProperty(exports,"__esModule",{value:!0}),t.prototype={on:function(t,e,i,n){return null==this._events&&(this._events=[]),this._events.push({event:t,fn:e,scope:i,once:n}),this},once:function(t,e,i){return this.on(t,e,i,!0)},off:function(t,e,i){var n=this;if(null==this._events)return this;for(var r=null==e,s=0;s<this._events.length;){var h=n._events[s];h.event===t&&(r||h.fn===e&&h.scope===i)?n._events.splice(s,1):s+=1}return this},removeAllListeners:function(){this._events=null},_emit:function(t,e){var i=this;if(null==this._events)return this;for(var n=0;n<this._events.length;){var r=i._events[n];r.event===t&&(r.fn.call(r.scope||i,e),r.once)?i._events.splice(n,1):n+=1}return this}};var x=0,z="_action",k=function(){return this.done};i.prototype={root:null,focus:null,head:null,size:0,limit:0,addRepo:function(t){this.repos.push(t)},removeRepo:function(t){this.repos=this.repos.filter(function(e){return e!=t})},invoke:function(t,e){for(var i=this.repos,n=0,r=i.length;n<r;n++)i[n][t](e)},checkout:function(t){return this.head=t,t?t.parent&&(t.parent.next=t):this.root=this.head=null,this.adjustSize(),this.invalidate(),this},append:function(t){var e=new p(t,this);return this.head?(e.parent=this.head,this.head.first?this.head.next.sibling=e:this.head.first=e,this.head.next=e):this.root=e,this.head=e,this.size+=1,this.head},invalidate:function(){this.focus=null,this.invoke("unarchive",null),this.reconcile()},reconcile:function(t){return!(this.repos.length<=0)&&(this.invoke("rollback",null),this.rollforward(),void this.invoke("release",t))},rollforward:function(){for(var t=this,e=this.focus?this.focus.next:this.root,i=!0;e&&e.parent!==this.head;)e.disabled||t.invoke("reconcile",e),i&&e.disposable?(t.focus=e,t.invoke("cache",t.archive())):i=!1,e=e.next},archive:function(){var t=this.size>this.limit;return t&&(this.size-=1,this.size<=0?this.root=this.head=this.focus=null:(this.root=this.root.next,this.root.parent=null)),t},adjustSize:function(){for(var t=this.head,e=this.root?1:0;t&&t.parent;){var i=t.parent;i.next=t,t=i,e+=1}this.size=e},forEach:function(t,e){for(var i=this,n=this.focus||this.root;n&&(t.call(e,n),n!==i.head);)n=n.next},map:function(t,e){var i=[];return this.forEach(function(n){i.push(t.call(e,n))}),i},toArray:function(){return this.map(function(t){return t})}};var j=Object.prototype.hasOwnProperty;s(p,t,{type:null,payload:void 0,disabled:!1,disposable:!1,parent:null,first:null,next:null,sibling:null,is:function(t){return this.type===this.behavior[t]},open:function(t){return this.disposable||(this.type=this.behavior.open,arguments.length>0&&(this.payload=t),this.history.reconcile(this),this._emit("open",this.payload)),this},send:function(t){return this.disposable||(this.type=this.behavior.loading,arguments.length>0&&(this.payload=t),this.history.reconcile(this),this._emit("update",this.payload)),this},reject:function(t){return this.disposable||(this.type=this.behavior.error,this.disposable=!0,arguments.length>0&&(this.payload=t),this.history.reconcile(this),this._emit("error",this.payload)),this},resolve:function(t){return this.disposable||(this.type=this.behavior.done,this.disposable=!0,arguments.length>0&&(this.payload=t),this.history.reconcile(this),this._emit("done",this.payload)),this},cancel:function(t){return this.disposable||(this.type=this.behavior.cancelled,this.disposable=!0,arguments.length>0&&(this.payload=t),this.history.reconcile(this),this._emit("cancel",this.payload)),this},toggle:function(){return this.disabled=!this.disabled,this.history.invalidate(),this},onError:function(t,e){return t?(this.is("error")?t.call(e,this.payload):this.once("error",t,e),this):this},onUpdate:function(t,e){return t?(this.on("update",t,e),this):this},onDone:function(t,e){return t?(this.is("done")?t.call(e,this.payload):this.once("done",t,e),this):this},onCancel:function(t,e){return t?(this.is("cancelled")?t.call(e,this.payload):this.once("cancel",t,e),this):this},then:function(t,e){var i=this;return new Promise(function(t,e){i.onDone(t),i.onError(e)}).then(t,e)}}),Object.defineProperty(p.prototype,"children",{get:function(){for(var t=[],e=this.first;e;)t.unshift(e),e=e.sibling;return t}}),d.prototype={handleReset:function(t,e){return e},handlePatch:function(t,e){return r(t,e)},handleRebase:function(t,e){return r(e,t)},register:function(){var t={};return t[this.reset]=this.handleReset,t[this.patch]=this.handlePatch,t[this.rebase]=this.handleRebase,t}};var S={getInitialState:"getInitialState",serialize:"serialize",deserialize:"deserialize"};y.prototype={register:function(t){return null==this.registry[t]&&(this.registry[t]=v(this.domains,t)),this.registry[t]},add:function(t,e,i){var n=null;return n="function"==typeof e?new e(i):Object.create(e),this.domains.push([t,n]),this.registry={},n.setup&&n.setup(this.repo,i),n.teardown&&this.repo.on("teardown",n.teardown,n),n},reset:function(t,e){return this.repo.push(this.meta.reset,t,e)},patch:function(t,e){return this.repo.push(this.meta.patch,t,e)},rebase:function(t){return this.repo.push(this.meta.rebase,t)}},s(_,t,{setup:function(){},teardown:function(){this._emit("teardown",this),this.history.removeRepo(this),this.removeAllListeners()},getInitialState:function(){return this.dispatch({},S.getInitialState,null)},dispatch:function(t,e,i){for(var n=this.realm.register(e),r=t,s=0,o=n.length;s<o;s++){var u=n[s],l=u.key,c=u.domain,f=u.handler,p=u.length,d=null;switch(p){case 0:d=f.call(c);break;case 1:d=f.call(c,h(t,l));break;case 2:default:d=f.call(c,h(t,l),i)}r=a(r,l,d)}return r},unarchive:function(){this.cached=this.archived},rollback:function(){this.staged=this.cached},cache:function(t){this.cached=this.staged,t&&(this.archived=this.cached)},commit:function(t){for(var e=this,i=this.realm.domains,n=t,r=0,s=i.length;r<s;r++){var h=i[r],o=h[0],a=h[1];n=e.write(n,o,a)}return n},write:function(t,e,i){if(null!=i.commit){var n=h(t,e);if(null!=i.shouldCommit){var r=h(this.cached,e);if(!i.shouldCommit(r,n))return a(t,e,h(this.state,e))}return a(t,e,i.commit(n,t))}return t},reconcile:function(t){if(this.follower)return this.state=this.parent.state,this.dirty=this.parent.dirty,this;var e=this.state;return this.parent&&(this.staged=r(this.staged,this.parent.state),this.state=r(this.state,this.parent.state)),this.staged=this.dispatch(this.staged,t.type,t.payload),this.state=this.commit(this.staged),this.state!=e&&(this.dirty=!0),this},release:function(t){t&&this._emit("effect",t),this.dirty&&(this.dirty=!1,this._emit("change",this.state))},append:function(t){return this.history.append(t)},push:function(t){for(var e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];var n=this.append(t);return w(n,n.behavior.apply(null,e),this),n},prepare:function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];return(i=this.push).bind.apply(i,[this].concat(t));var i},addDomain:function(t,e,i){return this.follower=!1,this.realm.add(t,e,i),this.rebase(),this},addEffect:function(t,e){return m(this,t,e),this},reset:function(t,e){return this.follower=!1,this.realm.reset(t,e)},patch:function(t,e){return this.follower=!1,this.realm.patch(t,e)},deserialize:function(t){var e=t?t:{};return"string"==typeof e&&(e=JSON.parse(e)),this.parent&&(e=this.parent.deserialize(e)),this.dispatch(e,S.deserialize,e)},serialize:function(){var t=this.staged;return this.parent&&(t=r(t,this.parent.serialize())),this.dispatch(t,S.serialize,null)},toJSON:function(){return this.serialize()},rebase:function(){var t=this.getInitialState();return this.cached=r(this.cached,t),this.realm.rebase(t)},checkout:function(t){return this.cached=this.archived,this.history.checkout(t),this},fork:function(){return new _({parent:this})},index:function(t,e){for(var i=this,n=[],r=arguments.length-2;r-- >0;)n[r]=arguments[r+2];var s=c(e),h=null,o=null,a=null,u=this.indexes[t]=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];if(i.state!==h){h=i.state;var r=f(h,s,o);r!==o&&(o=r,a=n.reduce(function(t,e){return e.call(i,t,h)},o))}return t.reduce(function(t,e){return e.call(i,t,h)},a)};return u},lookup:function(t){var e=this.indexes[t];if(null==e){if(this.parent)return this.parent.lookup(t);throw new TypeError("Unable to find missing index "+t)}return e},compute:function(t){for(var e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];return this.lookup(t).apply(void 0,e)},memo:function(t){for(var e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];var n=this.lookup(t),r=null,s=null;return function(){var t=n();return t!==r&&(r=t,s=n.apply(void 0,e)),s}}}),exports.default=_,exports.Microcosm=_,exports.Action=p,exports.History=i,exports.tag=e,exports.get=h,exports.set=a,exports.merge=r,exports.inherit=s;
"use strict";function t(){this._events=null}function e(t,e){if(null==t)throw new Error("Unable to identify "+t+" action");if(t.done)return t;"string"==typeof t&&(e=t,t=function(t){return t}),x+=1;var i=e||(t.name||z)+"."+x;return t.open=i+".open",t.loading=i+".loading",t.update=t.loading,t.done=i,t.resolve=t.done,t.error=i+".error",t.reject=t.error,t.cancelled=i+".cancelled",t.cancel=t.cancelled,t.toString=k,t}function i(t){void 0===t&&(t=0),this.repos=[],this.limit=t}function n(t){if(Array.isArray(t))return t.slice(0);var e={};for(var i in t)e[i]=t[i];return e}function r(t){for(var e=arguments,i=t,r=1,s=arguments.length;r<s;r++){var o=e[r];for(var h in o)i[h]!==o[h]&&(i===t&&(i=n(t)),i[h]=o[h])}return i}function s(t,e,i){return t.__proto__=e,t.prototype=r(Object.create(e.prototype),{constructor:t},i),t}function o(t,e,i){return null==t?i:null==e?t:Array.isArray(e)?h(t,e,i):j.call(t,e)?t[e]:i}function h(t,e,i){for(var n=t,r=0,s=e.length;r<s;r++)n=o(n,e[r],i);return n}function a(t,e,i){if(Array.isArray(e))return u(t,e,i);if(null==e)return i;if(void 0===i||o(t,e)===i)return t;var r=n(t);return r[e]=i,r}function u(t,e,i){if(h(t,e)===i)return t;var r=e[0],s=e.slice(1),o=n(t);return s.length?o[r]=r in o?u(o[r],s,i):u({},s,i):o[r]=i,o}function l(t){return t.split(/\./)}function c(t){var e=t.split(/\s*\,\s*/);return e.map(l)}function f(t,e,i){return e.reduce(function(e,i){return a(e,i,o(t,i))},i||{})}function d(n,r){t.call(this),this.behavior=e(n),this.history=r||new i}function p(){this.reset=function(t,e){return function(i,n){var s=n.getInitialState(),o=t;e&&(o=n.deserialize(t)),i.resolve(r(s,o))}},this.patch=function(t,e){return function(i,n){var r=t;e&&(r=n.deserialize(r)),i.resolve(r)}},this.rebase=function(t){return t}}function v(t,e){for(var i=[],n=null!=S[e],r=0,s=t.length;r<s;r++){var o=t[r],h=o[0],a=o[1],u=null;n&&null!=a[e]?u=a[e]:null!=a.register&&(u=a.register()[e]),u&&i.push({key:h,domain:a,handler:u,length:u.length})}return i}function y(t){this.repo=t,this.domains=[],this.registry={},this.meta=this.add(null,p)}function g(t,e){return function(i){var n=e.register()[i.type];n&&n.call(e,t,i.payload)}}function m(t,e,i){var n=null;n="function"==typeof e?new e(t,i):Object.create(e),n.setup&&n.setup(t,i),n.register&&t.on("effect",g(t,n)),n.teardown&&t.on("teardown",n.teardown,n)}function b(t,e){return!!t&&("object"===e||"function"===e)&&"function"==typeof t.then}function w(t,e,i){var n=typeof e;return b(e,n)?(t.open(),e.then(function(e){return global.setTimeout(function(){return t.resolve(e)},0)},function(e){return global.setTimeout(function(){return t.reject(e)},0)}),t):"function"===n?(e(t,i),t):t.resolve(e)}function _(e,n,r){t.call(this),e=e||{},this.parent=e.parent||null,this.history=this.parent?this.parent.history:new i(e.maxHistory),this.history.addRepo(this),this.realm=new y(this),this.archived=this.parent?this.parent.archived:{},this.cached=this.parent?this.parent.cached:this.archived,this.staged=this.parent?this.parent.state:this.cached,this.state=this.parent?this.parent.state:this.staged,this.follower=!!this.parent,this.indexes={},this.dirty=!1,this.setup(e),n&&this.reset(n,r)}Object.defineProperty(exports,"__esModule",{value:!0}),t.prototype={on:function(t,e,i,n){return null==this._events&&(this._events=[]),this._events.push({event:t,fn:e,scope:i,once:n}),this},once:function(t,e,i){return this.on(t,e,i,!0)},off:function(t,e,i){var n=this;if(null==this._events)return this;for(var r=null==e,s=0;s<this._events.length;){var o=n._events[s];o.event===t&&(r||o.fn===e&&o.scope===i)?n._events.splice(s,1):s+=1}return this},removeAllListeners:function(){this._events=null},_emit:function(t,e){var i=this;if(null==this._events)return this;for(var n=0;n<this._events.length;){var r=i._events[n];r.event===t&&(r.fn.call(r.scope||i,e),r.once)?i._events.splice(n,1):n+=1}return this}};var x=0,z="_action",k=function(){return this.done};i.prototype={root:null,focus:null,head:null,size:0,limit:0,addRepo:function(t){this.repos.push(t)},removeRepo:function(t){this.repos=this.repos.filter(function(e){return e!=t})},invoke:function(t,e){for(var i=this.repos,n=0,r=i.length;n<r;n++)i[n][t](e)},checkout:function(t){return this.head=t,t?t.parent&&(t.parent.next=t):this.root=this.head=null,this.adjustSize(),this.invalidate(),this},append:function(t){var e=new d(t,this);return this.head?(e.parent=this.head,this.head.first?this.head.next.sibling=e:this.head.first=e,this.head.next=e):this.root=e,this.head=e,this.size+=1,this.head},invalidate:function(){this.focus=null,this.invoke("unarchive",null),this.reconcile()},reconcile:function(t){return!(this.repos.length<=0)&&(this.invoke("rollback",null),this.rollforward(),void this.invoke("release",t))},rollforward:function(){for(var t=this,e=this.focus?this.focus.next:this.root,i=!0;e&&e.parent!==this.head;)e.disabled||t.invoke("reconcile",e),i&&e.disposable?(t.focus=e,t.invoke("cache",t.archive())):i=!1,e=e.next},archive:function(){var t=this.size>this.limit;return t&&(this.size-=1,this.size<=0?this.root=this.head=this.focus=null:(this.root=this.root.next,this.root.parent=null)),t},adjustSize:function(){for(var t=this.head,e=this.root?1:0;t&&t.parent;){var i=t.parent;i.next=t,t=i,e+=1}this.size=e},forEach:function(t,e){for(var i=this,n=this.focus||this.root;n&&(t.call(e,n),n!==i.head);)n=n.next},map:function(t,e){var i=[];return this.forEach(function(n){i.push(t.call(e,n))}),i},toArray:function(){return this.map(function(t){return t})}};var j=Object.prototype.hasOwnProperty;s(d,t,{type:null,payload:void 0,disabled:!1,disposable:!1,parent:null,first:null,next:null,sibling:null,is:function(t){return this.type===this.behavior[t]},open:function(t){return this.disposable||(this.type=this.behavior.open,arguments.length>0&&(this.payload=t),this.history.reconcile(this),this._emit("open",this.payload)),this},update:function(t){return this.disposable||(this.type=this.behavior.loading,arguments.length>0&&(this.payload=t),this.history.reconcile(this),this._emit("update",this.payload)),this},send:function(){return"undefined"!=typeof console&&console.warn("`send` was deprecated in 11.6.0.","Please use `update` instead.","`send` will be removed in 12.0.0."),this.update.apply(this,arguments)},reject:function(t){return this.disposable||(this.type=this.behavior.error,this.disposable=!0,arguments.length>0&&(this.payload=t),this.history.reconcile(this),this._emit("error",this.payload)),this},resolve:function(t){return this.disposable||(this.type=this.behavior.done,this.disposable=!0,arguments.length>0&&(this.payload=t),this.history.reconcile(this),this._emit("done",this.payload)),this},cancel:function(t){return this.disposable||(this.type=this.behavior.cancelled,this.disposable=!0,arguments.length>0&&(this.payload=t),this.history.reconcile(this),this._emit("cancel",this.payload)),this},toggle:function(){return this.disabled=!this.disabled,this.history.invalidate(),this},onError:function(t,e){return t?(this.is("error")?t.call(e,this.payload):this.once("error",t,e),this):this},onUpdate:function(t,e){return t?(this.on("update",t,e),this):this},onDone:function(t,e){return t?(this.is("done")?t.call(e,this.payload):this.once("done",t,e),this):this},onCancel:function(t,e){return t?(this.is("cancelled")?t.call(e,this.payload):this.once("cancel",t,e),this):this},then:function(t,e){var i=this;return new Promise(function(t,e){i.onDone(t),i.onError(e)}).then(t,e)}}),Object.defineProperty(d.prototype,"children",{get:function(){for(var t=[],e=this.first;e;)t.unshift(e),e=e.sibling;return t}}),p.prototype={handleReset:function(t,e){return e},handlePatch:function(t,e){return r(t,e)},handleRebase:function(t,e){return r(e,t)},register:function(){var t={};return t[this.reset]=this.handleReset,t[this.patch]=this.handlePatch,t[this.rebase]=this.handleRebase,t}};var S={getInitialState:"getInitialState",serialize:"serialize",deserialize:"deserialize"};y.prototype={register:function(t){return null==this.registry[t]&&(this.registry[t]=v(this.domains,t)),this.registry[t]},add:function(t,e,i){var n=null;return n="function"==typeof e?new e(i):Object.create(e),this.domains.push([t,n]),this.registry={},n.setup&&n.setup(this.repo,i),n.teardown&&this.repo.on("teardown",n.teardown,n),n},reset:function(t,e){return this.repo.push(this.meta.reset,t,e)},patch:function(t,e){return this.repo.push(this.meta.patch,t,e)},rebase:function(t){return this.repo.push(this.meta.rebase,t)}},s(_,t,{setup:function(){},teardown:function(){this._emit("teardown",this),this.history.removeRepo(this),this.removeAllListeners()},getInitialState:function(){return this.dispatch({},S.getInitialState,null)},dispatch:function(t,e,i){for(var n=this.realm.register(e),r=t,s=0,h=n.length;s<h;s++){var u=n[s],l=u.key,c=u.domain,f=u.handler,d=u.length,p=null;switch(d){case 0:p=f.call(c);break;case 1:p=f.call(c,o(t,l));break;case 2:default:p=f.call(c,o(t,l),i)}r=a(r,l,p)}return r},unarchive:function(){this.cached=this.archived},rollback:function(){this.staged=this.cached},cache:function(t){this.cached=this.staged,t&&(this.archived=this.cached)},commit:function(t){for(var e=this,i=this.realm.domains,n=t,r=0,s=i.length;r<s;r++){var o=i[r],h=o[0],a=o[1];n=e.write(n,h,a)}return n},write:function(t,e,i){if(null!=i.commit){var n=o(t,e);if(null!=i.shouldCommit){var r=o(this.cached,e);if(!i.shouldCommit(r,n))return a(t,e,o(this.state,e))}return a(t,e,i.commit(n,t))}return t},reconcile:function(t){if(this.follower)return this.state=this.parent.state,this.dirty=this.parent.dirty,this;var e=this.state;return this.parent&&(this.staged=r(this.staged,this.parent.state),this.state=r(this.state,this.parent.state)),this.staged=this.dispatch(this.staged,t.type,t.payload),this.state=this.commit(this.staged),this.state!=e&&(this.dirty=!0),this},release:function(t){t&&this._emit("effect",t),this.dirty&&(this.dirty=!1,this._emit("change",this.state))},append:function(t){return this.history.append(t)},push:function(t){for(var e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];var n=this.append(t);return w(n,n.behavior.apply(null,e),this),n},prepare:function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];return(i=this.push).bind.apply(i,[this].concat(t));var i},addDomain:function(t,e,i){return this.follower=!1,this.realm.add(t,e,i),this.rebase(),this},addEffect:function(t,e){return m(this,t,e),this},reset:function(t,e){return this.follower=!1,this.realm.reset(t,e)},patch:function(t,e){return this.follower=!1,this.realm.patch(t,e)},deserialize:function(t){var e=t?t:{};return"string"==typeof e&&(e=JSON.parse(e)),this.parent&&(e=this.parent.deserialize(e)),this.dispatch(e,S.deserialize,e)},serialize:function(){var t=this.staged;return this.parent&&(t=r(t,this.parent.serialize())),this.dispatch(t,S.serialize,null)},toJSON:function(){return this.serialize()},rebase:function(){var t=this.getInitialState();return this.cached=r(this.cached,t),this.realm.rebase(t)},checkout:function(t){return this.cached=this.archived,this.history.checkout(t),this},fork:function(){return new _({parent:this})},index:function(t,e){for(var i=this,n=[],r=arguments.length-2;r-- >0;)n[r]=arguments[r+2];var s=c(e),o=null,h=null,a=null,u=this.indexes[t]=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];if(i.state!==o){o=i.state;var r=f(o,s,h);r!==h&&(h=r,a=n.reduce(function(t,e){return e.call(i,t,o)},h))}return t.reduce(function(t,e){return e.call(i,t,o)},a)};return u},lookup:function(t){var e=this.indexes[t];if(null==e){if(this.parent)return this.parent.lookup(t);throw new TypeError("Unable to find missing index "+t)}return e},compute:function(t){for(var e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];return this.lookup(t).apply(void 0,e)},memo:function(t){for(var e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];var n=this.lookup(t),r=null,s=null;return function(){var t=n();return t!==r&&(r=t,s=n.apply(void 0,e)),s}}}),exports.default=_,exports.Microcosm=_,exports.Action=d,exports.History=i,exports.tag=e,exports.get=o,exports.set=a,exports.merge=r,exports.inherit=s;
{
"name": "microcosm",
"version": "11.5.1",
"version": "11.6.0-rc.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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc