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

delorean.js

Package Overview
Dependencies
Maintainers
1
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

delorean.js - npm Package Compare versions

Comparing version 0.7.2 to 0.8.0

2

bower.json
{
"name": "delorean.js",
"version": "0.7.2",
"version": "0.8.0",
"homepage": "http://deloreanjs.com",

@@ -5,0 +5,0 @@ "authors": [

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

/*! delorean.js - v0.7.1 - 2014-09-20 */
/*! delorean.js - v0.7.2-4 - 2014-09-21 */
(function (DeLorean) {

@@ -11,3 +11,3 @@ 'use strict';

// ## Global Helper Functions
// ## Private Helper Functions

@@ -17,3 +17,3 @@ // Helper functions are private functions to be used in codebase.

// `__hasOwn` function is a shortcut for `Object#hasOwnProperty`.
/* `__hasOwn` function is a shortcut for `Object#hasOwnProperty` */
function __hasOwn(object, prop) {

@@ -30,6 +30,12 @@ return Object.prototype.hasOwnProperty.call(object, prop);

/* It's used by the schemes to save the original version (not calculated)
of the data. */
function __generateOriginalName(name) {
return 'original:' + name;
}
// `__findDispatcher` is a private function for **React components**.
// `view` should be a component instance. If a component don't have
// any dispatcher, it tries to find a dispatcher from the parents.
function __findDispatcher(view) {
/* `view` should be a component instance. If a component don't have
any dispatcher, it tries to find a dispatcher from the parents. */
if (!view.props.dispatcher) {

@@ -53,4 +59,3 @@ return __findDispatcher(view._owner);

// Rollback listener adds a `rollback` event listener to the bunch of
// stores. If any of them fires `rollback` event, all of the stores
// will be emitted to be rolled back with `__rollback` event.
// stores.
function __rollbackListener(stores) {

@@ -64,2 +69,4 @@

/* If any of them fires `rollback` event, all of the stores
will be emitted to be rolled back with `__rollback` event. */
for (var j in stores) {

@@ -78,3 +85,3 @@ stores[j].listener.on('rollback', __listener);

// Stores should be listened for rollback events.
/* Stores should be listened for rollback events. */
__rollbackListener(Object.keys(stores).map(function (key) {

@@ -89,3 +96,3 @@ return stores[key];

// Stores are key-value pairs. Collect store instances into an array.
/* Stores are key-value pairs. Collect store instances into an array. */
stores = (function () {

@@ -95,3 +102,3 @@ var stores = [], store;

store = self.stores[storeName];
// Store value must be an _instance of Store_.
/* Store value must be an _instance of Store_. */
if (!store instanceof Store) {

@@ -109,3 +116,3 @@ throw 'Given store is not a store instance';

// Payload should send to all related stores.
/* Payload should send to all related stores. */
for (var storeName in self.stores) {

@@ -115,3 +122,4 @@ self.stores[storeName].dispatchAction(actionName, data);

// And so you can just use **promise** for dispatching: `dispatch(..).then(..)`.
// `dispatch` returns deferred object you can just use **promise**
// for dispatching: `dispatch(..).then(..)`.
return deferred;

@@ -129,4 +137,4 @@ };

// `__promiseGenerator` generates a simple promise that resolves itself when
// related store is changed.
/* `__promiseGenerator` generates a simple promise that resolves itself when
related store is changed. */
function __promiseGenerator(store) {

@@ -155,3 +163,3 @@ // `DeLorean.Promise` is `require('es6-promise').Promise` by default.

Dispatcher.prototype.registerAction = function (action, callback) {
// The callback must be a function.
/* The callback must be a function. */
if (typeof callback === 'function') {

@@ -203,3 +211,3 @@ this[action] = callback.bind(this.stores);

function Store(store, args) {
// store parameter must be an `object`
/* store parameter must be an `object` */
if (typeof store !== 'object') {

@@ -213,7 +221,9 @@ throw 'Stores should be defined by passing the definition to the constructor';

// Store is _hygenic_ object. DeLorean doesn't extend it, it uses it.
/* Store is _hygenic_ object. DeLorean doesn't extend it, it uses it. */
this.store = store;
this.bindActions();
this.buildScheme();
// `initialize` is the construction function.
// `initialize` is the construction function, you can define `initialize` method
// in your store definitions.
if (typeof store.initialize === 'function') {

@@ -224,2 +234,87 @@ store.initialize.apply(this.store, args);

Store.prototype.set = function (key, value) {
var scheme = this.store.scheme, definition;
if (scheme && this.store.scheme[key]) {
definition = scheme[key];
this.store[key] = value || definition.default;
if (typeof definition.calculate === 'function') {
this.store[__generateOriginalName(key)] = value;
this.store[key] = definition.calculate.call(this.store, value);
}
this.recalculate();
} else {
throw 'Scheme should include the key ' + key + ' you wanted to set.';
}
return this.store[key];
};
// Removes the scheme format and standardizes all the shortcuts.
// If you run `formatScheme({name: 'joe'})` it will return you
// `{name: {default: 'joe'}}`. Also if you run `formatScheme({fullname: function () {}})`
// it will return `{fullname: {calculate: function () {}}}`.
Store.prototype.formatScheme = function (scheme) {
var formattedScheme = {};
for (var keyName in scheme) {
var definition = scheme[keyName], defaultValue, calculatedValue;
formattedScheme[keyName] = {default: null};
/* {key: 'value'} will be {key: {default: 'value'}} */
defaultValue = (typeof definition === 'object') ?
definition.default : definition;
formattedScheme[keyName].default = defaultValue;
/* {key: function () {}} will be {key: {calculate: function () {}}} */
if (typeof definition.calculate === 'function') {
calculatedValue = definition.calculate;
} else if (typeof definition === 'function') {
calculatedValue = definition;
}
if (calculatedValue) {
formattedScheme[keyName].calculate = calculatedValue;
}
}
return formattedScheme;
};
/* Applying `scheme` to the store if exists. */
Store.prototype.buildScheme = function () {
var scheme, calculatedData, keyName, definition;
if (typeof this.store.scheme === 'object') {
/* Scheme must be formatted to standardize the keys. */
scheme = this.store.scheme = this.formatScheme(this.store.scheme);
/* Set the defaults first */
for (keyName in scheme) {
definition = scheme[keyName];
this.store[keyName] = definition.default;
}
/* Set the calculations */
for (keyName in scheme) {
definition = scheme[keyName];
if (definition.calculate) {
this.store[__generateOriginalName(keyName)] = definition.default;
this.store[keyName] = definition.calculate.call(this.store, definition.default);
}
}
}
};
Store.prototype.recalculate = function () {
var scheme = this.store.scheme, definition, keyName;
for (keyName in scheme) {
definition = scheme[keyName];
if (typeof definition.calculate === 'function') {
this.store[keyName] = definition.calculate.call(this.store,
this.store[__generateOriginalName(keyName)] || definition.default);
}
}
this.listener.emit('change');
};
// `bindActions` is semi-private method. You'll never need to call it from outside.

@@ -230,3 +325,4 @@ // It powers up the `this.store` object.

// Some required methods can be used in **store definition**.
// Some required methods can be used in **store definition** like
// **`emit`**, **`emitChange`**, **`emitRollback`**, **`rollback`**, **`listenChanges`**
this.store.emit = this.listener.emit.bind(this.listener);

@@ -237,6 +333,6 @@ this.store.emitChange = this.listener.emit.bind(this.listener, 'change');

this.store.listenChanges = this.listenChanges.bind(this);
this.store.set = this.set.bind(this);
// Stores must have a `actions` hash of `actionName: methodName`
// `methodName` is the `this.store`'s prototype method. And `actionName`
// should be a name generated by `__generateActionName`.
// `methodName` is the `this.store`'s prototype method..
for (var actionName in this.store.actions) {

@@ -248,2 +344,3 @@ if (__hasOwn(this.store.actions, actionName)) {

}
/* And `actionName` should be a name generated by `__generateActionName` */
this.listener.on(__generateActionName(actionName),

@@ -301,3 +398,3 @@ this.store[callback].bind(this.store));

// `createDispatcher` generates a dispatcher with actions to dispatch.
// `actionsToDispatch` should be an object.
/* `actionsToDispatch` should be an object. */
createDispatcher: function (actionsToDispatch) {

@@ -311,9 +408,9 @@ var actionsOfStores, dispatcher, callback;

// If there are no stores defined, it's an empty object.
/* If there are no stores defined, it's an empty object. */
dispatcher = new Dispatcher(actionsOfStores || {});
// Now call `registerAction` method for every action.
/* Now call `registerAction` method for every action. */
for (var actionName in actionsToDispatch) {
if (__hasOwn(actionsToDispatch, actionName)) {
// `getStores` is the special function, it's not an action.
/* `getStores` is the special function, it's not an action. */
if (actionName !== 'getStores') {

@@ -351,8 +448,7 @@ callback = actionsToDispatch[actionName];

// `__changeHandler` is a **listener generator** to pass to the `onChange`
// function.
/* `__changeHandler` is a **listener generator** to pass to the `onChange` function. */
function __changeHandler(store, storeName) {
return function () {
var state, args;
// Call the components `storeDidChanged` method if exists.
// When something changes it calls the components `storeDidChanged` method if exists.
if (self.storeDidChange) {

@@ -362,3 +458,3 @@ args = [storeName].concat(Array.prototype.slice.call(arguments, 0));

}
// If the component is mounted, change state.
/* If the component is mounted, change state. */
if (self.isMounted()) {

@@ -370,3 +466,3 @@ self.setState(self.getStoreStates());

// Generate and bind the change handlers to the stores.
/* Generate and bind the change handlers to the stores. */
for (var storeName in this.stores) {

@@ -380,3 +476,3 @@ if (__hasOwn(this.stores, storeName)) {

// When a component unmounted, it should stop listening. (TODO)
// When a component unmounted, it should stop listening.
componentWillUnmount: function () {

@@ -386,3 +482,3 @@ for (var storeName in this.stores) {

var store = this.stores[storeName];
// TODO: What if another mounted view listening this store? Commenting out for now.
/* FIXME: What if another mounted view listening this store? Commenting out for now. */
store.listener.removeAllListeners('change');

@@ -396,4 +492,4 @@ }

// The dispatcher should be easy to access and it should use `__findDispatcher`
// method to find the parent dispatchers.
/* The dispatcher should be easy to access and it should use `__findDispatcher`
method to find the parent dispatchers. */
this.dispatcher = __findDispatcher(this);

@@ -410,2 +506,3 @@

// Since `dispatcher.stores` is harder to write, there's a shortcut for it.
// You can use `this.stores` from the React component.
this.stores = this.dispatcher.stores;

@@ -419,3 +516,3 @@

// Set `state.stores` for all present stores with a `setState` method defined.
/* Set `state.stores` for all present stores with a `setState` method defined. */
for (var storeName in this.stores) {

@@ -428,2 +525,7 @@ if (__hasOwn(this.stores, storeName)) {

state.stores[storeName] = this.stores[storeName].store.getState();
} else if (typeof this.stores[storeName].store.scheme === 'object') {
var scheme = this.stores[storeName].store.scheme;
for (var keyName in scheme) {
state.stores[storeName] = this.stores[storeName].store[keyName];
}
}

@@ -430,0 +532,0 @@ }

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

!function(DeLorean){"use strict";function a(a,b){return Object.prototype.hasOwnProperty.call(a,b)}function b(a){return"action:"+a}function c(a){return a.props.dispatcher?a.props.dispatcher:c(a._owner)}var Dispatcher,Store;if(Dispatcher=function(){function a(a){function b(){for(var b in a)a[b].listener.emit("__rollback")}for(var c in a)a[c].listener.on("rollback",b)}function Dispatcher(b){this.listener=new DeLorean.EventEmitter,this.stores=b,a(Object.keys(b).map(function(a){return b[a]}))}return Dispatcher.prototype.dispatch=function(a,b){var c,d,e=this;c=function(){var a,b=[];for(var c in e.stores){if(a=e.stores[c],!a instanceof Store)throw"Given store is not a store instance";b.push(a)}return b}(),d=this.waitFor(c);for(var f in e.stores)e.stores[f].dispatchAction(a,b);return d},Dispatcher.prototype.waitFor=function(a){var b,c=this;return b=function(){function b(a){return new DeLorean.Promise(function(b){a.listener.once("change",b)})}var c,d=[];for(var e in a)c=b(a[e]),d.push(c);return d}(),DeLorean.Promise.all(b).then(function(){c.listener.emit("change:all")})},Dispatcher.prototype.registerAction=function(a,b){if("function"!=typeof b)throw"Action callback should be a function.";this[a]=b.bind(this.stores)},Dispatcher.prototype.getStore=function(a){if(!this.stores[a])throw"Store "+a+" does not exist.";return this.stores[a].store},Dispatcher.prototype.on=function(){return this.listener.on.apply(this.listener,arguments)},Dispatcher.prototype.off=function(){return this.listener.removeListener.apply(this.listener,arguments)},Dispatcher.prototype.emit=function(){return this.listener.emit.apply(this.listener,arguments)},Dispatcher}(),Store=function(){function Store(a,b){if("object"!=typeof a)throw"Stores should be defined by passing the definition to the constructor";this.listener=new DeLorean.EventEmitter,this.store=a,this.bindActions(),"function"==typeof a.initialize&&a.initialize.apply(this.store,b)}return Store.prototype.bindActions=function(){var c;this.store.emit=this.listener.emit.bind(this.listener),this.store.emitChange=this.listener.emit.bind(this.listener,"change"),this.store.emitRollback=this.listener.emit.bind(this.listener,"rollback"),this.store.rollback=this.listener.on.bind(this.listener,"__rollback"),this.store.listenChanges=this.listenChanges.bind(this);for(var d in this.store.actions)if(a(this.store.actions,d)){if(c=this.store.actions[d],"function"!=typeof this.store[c])throw"Callback should be a method!";this.listener.on(b(d),this.store[c].bind(this.store))}},Store.prototype.dispatchAction=function(a,c){this.listener.emit(b(a),c)},Store.prototype.listenChanges=function(a){var b,c=this;return Object.observe?(b=Array.isArray(a)?Array.observe:Object.observe,void b(a,function(a){c.listener.emit("change",a)})):void console.error("Store#listenChanges method uses Object.observe, you should fire changes manually.")},Store.prototype.onChange=function(a){this.listener.on("change",a)},Store}(),DeLorean.Flux={createStore:function(a){return function(){return new Store(a,arguments)}},createDispatcher:function(b){var c,d,e;"function"==typeof b.getStores&&(c=b.getStores()),d=new Dispatcher(c||{});for(var f in b)a(b,f)&&"getStores"!==f&&(e=b[f],d.registerAction(f,e.bind(d)));return d},define:function(a,b){DeLorean[a]=b}},DeLorean.Dispatcher=Dispatcher,DeLorean.Store=Store,DeLorean.Flux.mixins={storeListener:{componentDidMount:function(){function b(a,b){return function(){var a;d.storeDidChange&&(a=[b].concat(Array.prototype.slice.call(arguments,0)),d.storeDidChange.apply(d,a)),d.isMounted()&&d.setState(d.getStoreStates())}}var c,d=this;for(var e in this.stores)a(this.stores,e)&&(c=this.stores[e],c.onChange(b(c,e)))},componentWillUnmount:function(){for(var b in this.stores)if(a(this.stores,b)){var c=this.stores[b];c.listener.removeAllListeners("change")}},getInitialState:function(){var a=this;return this.dispatcher=c(this),this.storesDidChange&&this.dispatcher.on("change:all",function(){a.storesDidChange()}),this.stores=this.dispatcher.stores,this.getStoreStates()},getStoreStates:function(){var b={stores:{}};for(var c in this.stores)a(this.stores,c)&&this.stores[c]&&this.stores[c].store&&this.stores[c].store.getState&&(b.stores[c]=this.stores[c].store.getState());return b},getStore:function(a){return this.state.stores[a]}}},"undefined"!=typeof module&&"undefined"!=typeof module.exports){var d=require("./requirements");for(var e in d)DeLorean.Flux.define(e,d[e]);module.exports=DeLorean}else"function"==typeof define&&define.amd?define([],function(){return DeLorean}):window.DeLorean=DeLorean}({}),function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){"use strict";var d=a("./promise/promise").Promise,e=a("./promise/polyfill").polyfill;c.Promise=d,c.polyfill=e},{"./promise/polyfill":5,"./promise/promise":6}],2:[function(a,b,c){"use strict";function d(a){var b=this;if(!e(a))throw new TypeError("You must pass an array to all.");return new b(function(b,c){function d(a){return function(b){e(a,b)}}function e(a,c){h[a]=c,0===--i&&b(h)}var g,h=[],i=a.length;0===i&&b([]);for(var j=0;j<a.length;j++)g=a[j],g&&f(g.then)?g.then(d(j),c):e(j,g)})}var e=a("./utils").isArray,f=a("./utils").isFunction;c.all=d},{"./utils":10}],3:[function(a,b,c){(function(a,b){"use strict";function d(){return function(){a.nextTick(g)}}function e(){var a=0,b=new k(g),c=document.createTextNode("");return b.observe(c,{characterData:!0}),function(){c.data=a=++a%2}}function f(){return function(){l.setTimeout(g,1)}}function g(){for(var a=0;a<m.length;a++){var b=m[a],c=b[0],d=b[1];c(d)}m=[]}function h(a,b){var c=m.push([a,b]);1===c&&i()}var i,j="undefined"!=typeof window?window:{},k=j.MutationObserver||j.WebKitMutationObserver,l="undefined"!=typeof b?b:void 0===this?window:this,m=[];i="undefined"!=typeof a&&"[object process]"==={}.toString.call(a)?d():k?e():f(),c.asap=h}).call(this,a("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{_process:12}],4:[function(a,b,c){"use strict";function d(a,b){return 2!==arguments.length?e[a]:void(e[a]=b)}var e={instrument:!1};c.config=e,c.configure=d},{}],5:[function(a,b,c){(function(b){"use strict";function d(){var a;a="undefined"!=typeof b?b:"undefined"!=typeof window&&window.document?window:self;var c="Promise"in a&&"resolve"in a.Promise&&"reject"in a.Promise&&"all"in a.Promise&&"race"in a.Promise&&function(){var b;return new a.Promise(function(a){b=a}),f(b)}();c||(a.Promise=e)}var e=a("./promise").Promise,f=a("./utils").isFunction;c.polyfill=d}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./promise":6,"./utils":10}],6:[function(a,b,c){"use strict";function d(a){if(!q(a))throw new TypeError("You must pass a resolver function as the first argument to the promise constructor");if(!(this instanceof d))throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");this._subscribers=[],e(a,this)}function e(a,b){function c(a){j(b,a)}function d(a){l(b,a)}try{a(c,d)}catch(e){d(e)}}function f(a,b,c,d){var e,f,g,h,k=q(c);if(k)try{e=c(d),g=!0}catch(m){h=!0,f=m}else e=d,g=!0;i(b,e)||(k&&g?j(b,e):h?l(b,f):a===y?j(b,e):a===z&&l(b,e))}function g(a,b,c,d){var e=a._subscribers,f=e.length;e[f]=b,e[f+y]=c,e[f+z]=d}function h(a,b){for(var c,d,e=a._subscribers,g=a._detail,h=0;h<e.length;h+=3)c=e[h],d=e[h+b],f(b,c,d,g);a._subscribers=null}function i(a,b){var c,d=null;try{if(a===b)throw new TypeError("A promises callback cannot return that same promise.");if(p(b)&&(d=b.then,q(d)))return d.call(b,function(d){return c?!0:(c=!0,void(b!==d?j(a,d):k(a,d)))},function(b){return c?!0:(c=!0,void l(a,b))}),!0}catch(e){return c?!0:(l(a,e),!0)}return!1}function j(a,b){a===b?k(a,b):i(a,b)||k(a,b)}function k(a,b){a._state===w&&(a._state=x,a._detail=b,o.async(m,a))}function l(a,b){a._state===w&&(a._state=x,a._detail=b,o.async(n,a))}function m(a){h(a,a._state=y)}function n(a){h(a,a._state=z)}var o=a("./config").config,p=(a("./config").configure,a("./utils").objectOrFunction),q=a("./utils").isFunction,r=(a("./utils").now,a("./all").all),s=a("./race").race,t=a("./resolve").resolve,u=a("./reject").reject,v=a("./asap").asap;o.async=v;var w=void 0,x=0,y=1,z=2;d.prototype={constructor:d,_state:void 0,_detail:void 0,_subscribers:void 0,then:function(a,b){var c=this,d=new this.constructor(function(){});if(this._state){var e=arguments;o.async(function(){f(c._state,d,e[c._state-1],c._detail)})}else g(this,d,a,b);return d},"catch":function(a){return this.then(null,a)}},d.all=r,d.race=s,d.resolve=t,d.reject=u,c.Promise=d},{"./all":2,"./asap":3,"./config":4,"./race":7,"./reject":8,"./resolve":9,"./utils":10}],7:[function(a,b,c){"use strict";function d(a){var b=this;if(!e(a))throw new TypeError("You must pass an array to race.");return new b(function(b,c){for(var d,e=0;e<a.length;e++)d=a[e],d&&"function"==typeof d.then?d.then(b,c):b(d)})}var e=a("./utils").isArray;c.race=d},{"./utils":10}],8:[function(a,b,c){"use strict";function d(a){var b=this;return new b(function(b,c){c(a)})}c.reject=d},{}],9:[function(a,b,c){"use strict";function d(a){if(a&&"object"==typeof a&&a.constructor===this)return a;var b=this;return new b(function(b){b(a)})}c.resolve=d},{}],10:[function(a,b,c){"use strict";function d(a){return e(a)||"object"==typeof a&&null!==a}function e(a){return"function"==typeof a}function f(a){return"[object Array]"===Object.prototype.toString.call(a)}var g=Date.now||function(){return(new Date).getTime()};c.objectOrFunction=d,c.isFunction=e,c.isArray=f,c.now=g},{}],11:[function(a,b){function c(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function d(a){return"function"==typeof a}function e(a){return"number"==typeof a}function f(a){return"object"==typeof a&&null!==a}function g(a){return void 0===a}b.exports=c,c.EventEmitter=c,c.prototype._events=void 0,c.prototype._maxListeners=void 0,c.defaultMaxListeners=10,c.prototype.setMaxListeners=function(a){if(!e(a)||0>a||isNaN(a))throw TypeError("n must be a positive number");return this._maxListeners=a,this},c.prototype.emit=function(a){var b,c,e,h,i,j;if(this._events||(this._events={}),"error"===a&&(!this._events.error||f(this._events.error)&&!this._events.error.length))throw b=arguments[1],b instanceof Error?b:TypeError('Uncaught, unspecified "error" event.');if(c=this._events[a],g(c))return!1;if(d(c))switch(arguments.length){case 1:c.call(this);break;case 2:c.call(this,arguments[1]);break;case 3:c.call(this,arguments[1],arguments[2]);break;default:for(e=arguments.length,h=new Array(e-1),i=1;e>i;i++)h[i-1]=arguments[i];c.apply(this,h)}else if(f(c)){for(e=arguments.length,h=new Array(e-1),i=1;e>i;i++)h[i-1]=arguments[i];for(j=c.slice(),e=j.length,i=0;e>i;i++)j[i].apply(this,h)}return!0},c.prototype.addListener=function(a,b){var e;if(!d(b))throw TypeError("listener must be a function");if(this._events||(this._events={}),this._events.newListener&&this.emit("newListener",a,d(b.listener)?b.listener:b),this._events[a]?f(this._events[a])?this._events[a].push(b):this._events[a]=[this._events[a],b]:this._events[a]=b,f(this._events[a])&&!this._events[a].warned){var e;e=g(this._maxListeners)?c.defaultMaxListeners:this._maxListeners,e&&e>0&&this._events[a].length>e&&(this._events[a].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[a].length),"function"==typeof console.trace&&console.trace())}return this},c.prototype.on=c.prototype.addListener,c.prototype.once=function(a,b){function c(){this.removeListener(a,c),e||(e=!0,b.apply(this,arguments))}if(!d(b))throw TypeError("listener must be a function");var e=!1;return c.listener=b,this.on(a,c),this},c.prototype.removeListener=function(a,b){var c,e,g,h;if(!d(b))throw TypeError("listener must be a function");if(!this._events||!this._events[a])return this;if(c=this._events[a],g=c.length,e=-1,c===b||d(c.listener)&&c.listener===b)delete this._events[a],this._events.removeListener&&this.emit("removeListener",a,b);else if(f(c)){for(h=g;h-->0;)if(c[h]===b||c[h].listener&&c[h].listener===b){e=h;break}if(0>e)return this;1===c.length?(c.length=0,delete this._events[a]):c.splice(e,1),this._events.removeListener&&this.emit("removeListener",a,b)}return this},c.prototype.removeAllListeners=function(a){var b,c;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[a]&&delete this._events[a],this;if(0===arguments.length){for(b in this._events)"removeListener"!==b&&this.removeAllListeners(b);return this.removeAllListeners("removeListener"),this._events={},this}if(c=this._events[a],d(c))this.removeListener(a,c);else for(;c.length;)this.removeListener(a,c[c.length-1]);return delete this._events[a],this},c.prototype.listeners=function(a){var b;return b=this._events&&this._events[a]?d(this._events[a])?[this._events[a]]:this._events[a].slice():[]},c.listenerCount=function(a,b){var c;return c=a._events&&a._events[b]?d(a._events[b])?1:a._events[b].length:0}},{}],12:[function(a,b){function c(){}var d=b.exports={};d.nextTick=function(){var a="undefined"!=typeof window&&window.setImmediate,b="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(a)return function(a){return window.setImmediate(a)};if(b){var c=[];return window.addEventListener("message",function(a){var b=a.source;if((b===window||null===b)&&"process-tick"===a.data&&(a.stopPropagation(),c.length>0)){var d=c.shift();d()}},!0),function(a){c.push(a),window.postMessage("process-tick","*")}}return function(a){setTimeout(a,0)}}(),d.title="browser",d.browser=!0,d.env={},d.argv=[],d.on=c,d.addListener=c,d.once=c,d.off=c,d.removeListener=c,d.removeAllListeners=c,d.emit=c,d.binding=function(){throw new Error("process.binding is not supported")},d.cwd=function(){return"/"},d.chdir=function(){throw new Error("process.chdir is not supported")}},{}],13:[function(a,b){var c;if(b.exports=c={EventEmitter:a("events").EventEmitter,Promise:a("es6-promise").Promise},"undefined"!=typeof DeLorean)for(var d in c)DeLorean.Flux.define(d,c[d])},{"es6-promise":1,events:11}]},{},[13]);
!function(DeLorean){"use strict";function a(a,b){return Object.prototype.hasOwnProperty.call(a,b)}function b(a){return"action:"+a}function c(a){return"original:"+a}function d(a){return a.props.dispatcher?a.props.dispatcher:d(a._owner)}var Dispatcher,Store;if(Dispatcher=function(){function a(a){function b(){for(var b in a)a[b].listener.emit("__rollback")}for(var c in a)a[c].listener.on("rollback",b)}function Dispatcher(b){this.listener=new DeLorean.EventEmitter,this.stores=b,a(Object.keys(b).map(function(a){return b[a]}))}return Dispatcher.prototype.dispatch=function(a,b){var c,d,e=this;c=function(){var a,b=[];for(var c in e.stores){if(a=e.stores[c],!a instanceof Store)throw"Given store is not a store instance";b.push(a)}return b}(),d=this.waitFor(c);for(var f in e.stores)e.stores[f].dispatchAction(a,b);return d},Dispatcher.prototype.waitFor=function(a){var b,c=this;return b=function(){function b(a){return new DeLorean.Promise(function(b){a.listener.once("change",b)})}var c,d=[];for(var e in a)c=b(a[e]),d.push(c);return d}(),DeLorean.Promise.all(b).then(function(){c.listener.emit("change:all")})},Dispatcher.prototype.registerAction=function(a,b){if("function"!=typeof b)throw"Action callback should be a function.";this[a]=b.bind(this.stores)},Dispatcher.prototype.getStore=function(a){if(!this.stores[a])throw"Store "+a+" does not exist.";return this.stores[a].store},Dispatcher.prototype.on=function(){return this.listener.on.apply(this.listener,arguments)},Dispatcher.prototype.off=function(){return this.listener.removeListener.apply(this.listener,arguments)},Dispatcher.prototype.emit=function(){return this.listener.emit.apply(this.listener,arguments)},Dispatcher}(),Store=function(){function Store(a,b){if("object"!=typeof a)throw"Stores should be defined by passing the definition to the constructor";this.listener=new DeLorean.EventEmitter,this.store=a,this.bindActions(),this.buildScheme(),"function"==typeof a.initialize&&a.initialize.apply(this.store,b)}return Store.prototype.set=function(a,b){var d,e=this.store.scheme;if(!e||!this.store.scheme[a])throw"Scheme should include the key "+a+" you wanted to set.";return d=e[a],this.store[a]=b||d.default,"function"==typeof d.calculate&&(this.store[c(a)]=b,this.store[a]=d.calculate.call(this.store,b)),this.recalculate(),this.store[a]},Store.prototype.formatScheme=function(a){var b={};for(var c in a){var d,e,f=a[c];b[c]={"default":null},d="object"==typeof f?f.default:f,b[c].default=d,"function"==typeof f.calculate?e=f.calculate:"function"==typeof f&&(e=f),e&&(b[c].calculate=e)}return b},Store.prototype.buildScheme=function(){var a,b,d;if("object"==typeof this.store.scheme){a=this.store.scheme=this.formatScheme(this.store.scheme);for(b in a)d=a[b],this.store[b]=d.default;for(b in a)d=a[b],d.calculate&&(this.store[c(b)]=d.default,this.store[b]=d.calculate.call(this.store,d.default))}},Store.prototype.recalculate=function(){var a,b,d=this.store.scheme;for(b in d)a=d[b],"function"==typeof a.calculate&&(this.store[b]=a.calculate.call(this.store,this.store[c(b)]||a.default));this.listener.emit("change")},Store.prototype.bindActions=function(){var c;this.store.emit=this.listener.emit.bind(this.listener),this.store.emitChange=this.listener.emit.bind(this.listener,"change"),this.store.emitRollback=this.listener.emit.bind(this.listener,"rollback"),this.store.rollback=this.listener.on.bind(this.listener,"__rollback"),this.store.listenChanges=this.listenChanges.bind(this),this.store.set=this.set.bind(this);for(var d in this.store.actions)if(a(this.store.actions,d)){if(c=this.store.actions[d],"function"!=typeof this.store[c])throw"Callback should be a method!";this.listener.on(b(d),this.store[c].bind(this.store))}},Store.prototype.dispatchAction=function(a,c){this.listener.emit(b(a),c)},Store.prototype.listenChanges=function(a){var b,c=this;return Object.observe?(b=Array.isArray(a)?Array.observe:Object.observe,void b(a,function(a){c.listener.emit("change",a)})):void console.error("Store#listenChanges method uses Object.observe, you should fire changes manually.")},Store.prototype.onChange=function(a){this.listener.on("change",a)},Store}(),DeLorean.Flux={createStore:function(a){return function(){return new Store(a,arguments)}},createDispatcher:function(b){var c,d,e;"function"==typeof b.getStores&&(c=b.getStores()),d=new Dispatcher(c||{});for(var f in b)a(b,f)&&"getStores"!==f&&(e=b[f],d.registerAction(f,e.bind(d)));return d},define:function(a,b){DeLorean[a]=b}},DeLorean.Dispatcher=Dispatcher,DeLorean.Store=Store,DeLorean.Flux.mixins={storeListener:{componentDidMount:function(){function b(a,b){return function(){var a;d.storeDidChange&&(a=[b].concat(Array.prototype.slice.call(arguments,0)),d.storeDidChange.apply(d,a)),d.isMounted()&&d.setState(d.getStoreStates())}}var c,d=this;for(var e in this.stores)a(this.stores,e)&&(c=this.stores[e],c.onChange(b(c,e)))},componentWillUnmount:function(){for(var b in this.stores)if(a(this.stores,b)){var c=this.stores[b];c.listener.removeAllListeners("change")}},getInitialState:function(){var a=this;return this.dispatcher=d(this),this.storesDidChange&&this.dispatcher.on("change:all",function(){a.storesDidChange()}),this.stores=this.dispatcher.stores,this.getStoreStates()},getStoreStates:function(){var b={stores:{}};for(var c in this.stores)if(a(this.stores,c))if(this.stores[c]&&this.stores[c].store&&this.stores[c].store.getState)b.stores[c]=this.stores[c].store.getState();else if("object"==typeof this.stores[c].store.scheme){var d=this.stores[c].store.scheme;for(var e in d)b.stores[c]=this.stores[c].store[e]}return b},getStore:function(a){return this.state.stores[a]}}},"undefined"!=typeof module&&"undefined"!=typeof module.exports){var e=require("./requirements");for(var f in e)DeLorean.Flux.define(f,e[f]);module.exports=DeLorean}else"function"==typeof define&&define.amd?define([],function(){return DeLorean}):window.DeLorean=DeLorean}({}),function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){"use strict";var d=a("./promise/promise").Promise,e=a("./promise/polyfill").polyfill;c.Promise=d,c.polyfill=e},{"./promise/polyfill":5,"./promise/promise":6}],2:[function(a,b,c){"use strict";function d(a){var b=this;if(!e(a))throw new TypeError("You must pass an array to all.");return new b(function(b,c){function d(a){return function(b){e(a,b)}}function e(a,c){h[a]=c,0===--i&&b(h)}var g,h=[],i=a.length;0===i&&b([]);for(var j=0;j<a.length;j++)g=a[j],g&&f(g.then)?g.then(d(j),c):e(j,g)})}var e=a("./utils").isArray,f=a("./utils").isFunction;c.all=d},{"./utils":10}],3:[function(a,b,c){(function(a,b){"use strict";function d(){return function(){a.nextTick(g)}}function e(){var a=0,b=new k(g),c=document.createTextNode("");return b.observe(c,{characterData:!0}),function(){c.data=a=++a%2}}function f(){return function(){l.setTimeout(g,1)}}function g(){for(var a=0;a<m.length;a++){var b=m[a],c=b[0],d=b[1];c(d)}m=[]}function h(a,b){var c=m.push([a,b]);1===c&&i()}var i,j="undefined"!=typeof window?window:{},k=j.MutationObserver||j.WebKitMutationObserver,l="undefined"!=typeof b?b:void 0===this?window:this,m=[];i="undefined"!=typeof a&&"[object process]"==={}.toString.call(a)?d():k?e():f(),c.asap=h}).call(this,a("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{_process:12}],4:[function(a,b,c){"use strict";function d(a,b){return 2!==arguments.length?e[a]:void(e[a]=b)}var e={instrument:!1};c.config=e,c.configure=d},{}],5:[function(a,b,c){(function(b){"use strict";function d(){var a;a="undefined"!=typeof b?b:"undefined"!=typeof window&&window.document?window:self;var c="Promise"in a&&"resolve"in a.Promise&&"reject"in a.Promise&&"all"in a.Promise&&"race"in a.Promise&&function(){var b;return new a.Promise(function(a){b=a}),f(b)}();c||(a.Promise=e)}var e=a("./promise").Promise,f=a("./utils").isFunction;c.polyfill=d}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./promise":6,"./utils":10}],6:[function(a,b,c){"use strict";function d(a){if(!q(a))throw new TypeError("You must pass a resolver function as the first argument to the promise constructor");if(!(this instanceof d))throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");this._subscribers=[],e(a,this)}function e(a,b){function c(a){j(b,a)}function d(a){l(b,a)}try{a(c,d)}catch(e){d(e)}}function f(a,b,c,d){var e,f,g,h,k=q(c);if(k)try{e=c(d),g=!0}catch(m){h=!0,f=m}else e=d,g=!0;i(b,e)||(k&&g?j(b,e):h?l(b,f):a===y?j(b,e):a===z&&l(b,e))}function g(a,b,c,d){var e=a._subscribers,f=e.length;e[f]=b,e[f+y]=c,e[f+z]=d}function h(a,b){for(var c,d,e=a._subscribers,g=a._detail,h=0;h<e.length;h+=3)c=e[h],d=e[h+b],f(b,c,d,g);a._subscribers=null}function i(a,b){var c,d=null;try{if(a===b)throw new TypeError("A promises callback cannot return that same promise.");if(p(b)&&(d=b.then,q(d)))return d.call(b,function(d){return c?!0:(c=!0,void(b!==d?j(a,d):k(a,d)))},function(b){return c?!0:(c=!0,void l(a,b))}),!0}catch(e){return c?!0:(l(a,e),!0)}return!1}function j(a,b){a===b?k(a,b):i(a,b)||k(a,b)}function k(a,b){a._state===w&&(a._state=x,a._detail=b,o.async(m,a))}function l(a,b){a._state===w&&(a._state=x,a._detail=b,o.async(n,a))}function m(a){h(a,a._state=y)}function n(a){h(a,a._state=z)}var o=a("./config").config,p=(a("./config").configure,a("./utils").objectOrFunction),q=a("./utils").isFunction,r=(a("./utils").now,a("./all").all),s=a("./race").race,t=a("./resolve").resolve,u=a("./reject").reject,v=a("./asap").asap;o.async=v;var w=void 0,x=0,y=1,z=2;d.prototype={constructor:d,_state:void 0,_detail:void 0,_subscribers:void 0,then:function(a,b){var c=this,d=new this.constructor(function(){});if(this._state){var e=arguments;o.async(function(){f(c._state,d,e[c._state-1],c._detail)})}else g(this,d,a,b);return d},"catch":function(a){return this.then(null,a)}},d.all=r,d.race=s,d.resolve=t,d.reject=u,c.Promise=d},{"./all":2,"./asap":3,"./config":4,"./race":7,"./reject":8,"./resolve":9,"./utils":10}],7:[function(a,b,c){"use strict";function d(a){var b=this;if(!e(a))throw new TypeError("You must pass an array to race.");return new b(function(b,c){for(var d,e=0;e<a.length;e++)d=a[e],d&&"function"==typeof d.then?d.then(b,c):b(d)})}var e=a("./utils").isArray;c.race=d},{"./utils":10}],8:[function(a,b,c){"use strict";function d(a){var b=this;return new b(function(b,c){c(a)})}c.reject=d},{}],9:[function(a,b,c){"use strict";function d(a){if(a&&"object"==typeof a&&a.constructor===this)return a;var b=this;return new b(function(b){b(a)})}c.resolve=d},{}],10:[function(a,b,c){"use strict";function d(a){return e(a)||"object"==typeof a&&null!==a}function e(a){return"function"==typeof a}function f(a){return"[object Array]"===Object.prototype.toString.call(a)}var g=Date.now||function(){return(new Date).getTime()};c.objectOrFunction=d,c.isFunction=e,c.isArray=f,c.now=g},{}],11:[function(a,b){function c(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function d(a){return"function"==typeof a}function e(a){return"number"==typeof a}function f(a){return"object"==typeof a&&null!==a}function g(a){return void 0===a}b.exports=c,c.EventEmitter=c,c.prototype._events=void 0,c.prototype._maxListeners=void 0,c.defaultMaxListeners=10,c.prototype.setMaxListeners=function(a){if(!e(a)||0>a||isNaN(a))throw TypeError("n must be a positive number");return this._maxListeners=a,this},c.prototype.emit=function(a){var b,c,e,h,i,j;if(this._events||(this._events={}),"error"===a&&(!this._events.error||f(this._events.error)&&!this._events.error.length))throw b=arguments[1],b instanceof Error?b:TypeError('Uncaught, unspecified "error" event.');if(c=this._events[a],g(c))return!1;if(d(c))switch(arguments.length){case 1:c.call(this);break;case 2:c.call(this,arguments[1]);break;case 3:c.call(this,arguments[1],arguments[2]);break;default:for(e=arguments.length,h=new Array(e-1),i=1;e>i;i++)h[i-1]=arguments[i];c.apply(this,h)}else if(f(c)){for(e=arguments.length,h=new Array(e-1),i=1;e>i;i++)h[i-1]=arguments[i];for(j=c.slice(),e=j.length,i=0;e>i;i++)j[i].apply(this,h)}return!0},c.prototype.addListener=function(a,b){var e;if(!d(b))throw TypeError("listener must be a function");if(this._events||(this._events={}),this._events.newListener&&this.emit("newListener",a,d(b.listener)?b.listener:b),this._events[a]?f(this._events[a])?this._events[a].push(b):this._events[a]=[this._events[a],b]:this._events[a]=b,f(this._events[a])&&!this._events[a].warned){var e;e=g(this._maxListeners)?c.defaultMaxListeners:this._maxListeners,e&&e>0&&this._events[a].length>e&&(this._events[a].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[a].length),"function"==typeof console.trace&&console.trace())}return this},c.prototype.on=c.prototype.addListener,c.prototype.once=function(a,b){function c(){this.removeListener(a,c),e||(e=!0,b.apply(this,arguments))}if(!d(b))throw TypeError("listener must be a function");var e=!1;return c.listener=b,this.on(a,c),this},c.prototype.removeListener=function(a,b){var c,e,g,h;if(!d(b))throw TypeError("listener must be a function");if(!this._events||!this._events[a])return this;if(c=this._events[a],g=c.length,e=-1,c===b||d(c.listener)&&c.listener===b)delete this._events[a],this._events.removeListener&&this.emit("removeListener",a,b);else if(f(c)){for(h=g;h-->0;)if(c[h]===b||c[h].listener&&c[h].listener===b){e=h;break}if(0>e)return this;1===c.length?(c.length=0,delete this._events[a]):c.splice(e,1),this._events.removeListener&&this.emit("removeListener",a,b)}return this},c.prototype.removeAllListeners=function(a){var b,c;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[a]&&delete this._events[a],this;if(0===arguments.length){for(b in this._events)"removeListener"!==b&&this.removeAllListeners(b);return this.removeAllListeners("removeListener"),this._events={},this}if(c=this._events[a],d(c))this.removeListener(a,c);else for(;c.length;)this.removeListener(a,c[c.length-1]);return delete this._events[a],this},c.prototype.listeners=function(a){var b;return b=this._events&&this._events[a]?d(this._events[a])?[this._events[a]]:this._events[a].slice():[]},c.listenerCount=function(a,b){var c;return c=a._events&&a._events[b]?d(a._events[b])?1:a._events[b].length:0}},{}],12:[function(a,b){function c(){}var d=b.exports={};d.nextTick=function(){var a="undefined"!=typeof window&&window.setImmediate,b="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(a)return function(a){return window.setImmediate(a)};if(b){var c=[];return window.addEventListener("message",function(a){var b=a.source;if((b===window||null===b)&&"process-tick"===a.data&&(a.stopPropagation(),c.length>0)){var d=c.shift();d()}},!0),function(a){c.push(a),window.postMessage("process-tick","*")}}return function(a){setTimeout(a,0)}}(),d.title="browser",d.browser=!0,d.env={},d.argv=[],d.on=c,d.addListener=c,d.once=c,d.off=c,d.removeListener=c,d.removeAllListeners=c,d.emit=c,d.binding=function(){throw new Error("process.binding is not supported")},d.cwd=function(){return"/"},d.chdir=function(){throw new Error("process.chdir is not supported")}},{}],13:[function(a,b){var c;if(b.exports=c={EventEmitter:a("events").EventEmitter,Promise:a("es6-promise").Promise},"undefined"!=typeof DeLorean)for(var d in c)DeLorean.Flux.define(d,c[d])},{"es6-promise":1,events:11}]},{},[13]);
//# sourceMappingURL=delorean.min.js.map

@@ -46,3 +46,3 @@ # Stores

You may define an `initialize` function to run setup code on construction. In `initialize`,
You may define an `initialize` function to run setup code on construction. In `initialize`,
you may **perform server actions**, *but **action creators** are a simpler entity for executing server actions.*

@@ -73,8 +73,72 @@

You must define a `getState` method on your store. This method should return an object
containing the state data needed by your view(s). It is called by the React mixin on
`componentDidMount`, and the returned data is placed into `this.state.stores[storeName]` on
React components with the Delorean `storeListener` mixin applied (see the [View (or React Component)](./views.md)
You must define a `getState` method on your store. This method should return an object
containing the state data needed by your view(s). It is called by the React mixin on
`componentDidMount`, and the returned data is placed into `this.state.stores[storeName]` on
React components with the Delorean `storeListener` mixin applied (see the [View (or React Component)](./views.md)
documentation for more).
### Advanced Data Structure with `scheme`
Schemes are simply structure definitions of the DeLorean.
```js
var Artist = Flux.createStore({
scheme: {
firstName: {
default: 'Unknown'
},
lastName: {
default: 'Artist'
},
fullName: {
calculate: function () {
return this.firstName + ' ' + this.lastName;
}
}
}
});
```
You can also write it simpler:
```js
var Artist = Flux.createStore({
scheme: {
firstName: 'Unknown',
lastName: 'Artist',
fullName: function () {
return this.firstName + ' ' + this.lastName;
}
}
});
```
#### `set` method to change data defined at `scheme`
You must use `set` method to mutate the data of the scheme. It'll change the
data and calls `emit('change')`
```js
var artist = new Artist();
artist.set('firstName', 'Michael');
artist.set('lastName', 'Jackson');
```
*Note: If you try to set a value doesn't exist in `scheme` it'll throw an error.*
In Todo example it may be better:
```js
var TodoStore = Flux.createStore({
scheme: {
todos: {
default: [],
calculate: function () {
return this.todos.concat().sort(function (a, b) { return a > b });
}
}
}
});
```
### `emitChange()` or `emit('change')`

@@ -81,0 +145,0 @@

@@ -12,6 +12,25 @@ /** @jsx React.DOM */

todos: [
{text: 'hello'},
{text: 'world'}
],
scheme: {
firstname: 'John',
surname: 'Doe',
fullname: {
default: 'woot',
calculate: function (value) {
return value.toUpperCase() + ' ' + this.firstname;
}
},
todos: {
default: [
{text: 'b'},
{text: 'c'},
{text: 'a'}
],
calculate: function () {
var self = this;
return this.todos.map(function (todo) {
return {text: todo.text.toString().toUpperCase()};
});
}
}
},

@@ -21,3 +40,3 @@ initialize: function (todos) {

if (todos) {
this.todos = this.todos.concat(todos);
this.todos = this.set('todos', this.todos.concat(todos));
}

@@ -39,3 +58,3 @@

addTodo: function (todo) {
this.todos.push({text: todo.text});
this.set('todos', this.todos.concat({text: todo.text}));
},

@@ -49,3 +68,3 @@

this.todos = filteredData;
this.set('todos', filteredData);
this.emit('change');

@@ -55,12 +74,7 @@ },

resetTodos: function (todos) {
this.todos = todos;
this.set('todos', todos);
this.listenChanges(this.todos);
this.emit('change');
},
}
getState: function () {
return {
todos: this.todos
}
}
});

@@ -212,5 +226,6 @@

return React.DOM.div(null,
React.DOM.span(null, this.dispatcher.getStore('todoStore').fullname),
TodoListView(null),
TodoFormView(null),
React.DOM.span(null, "There are ", this.stores.todoStore.store.todos.length, " todos.")
React.DOM.span(null, "There are ", this.dispatcher.getStore('todoStore').todos.length, " todos.")
)

@@ -217,0 +232,0 @@ }

@@ -12,6 +12,25 @@ /** @jsx React.DOM */

todos: [
{text: 'hello'},
{text: 'world'}
],
scheme: {
firstname: 'John',
surname: 'Doe',
fullname: {
default: 'woot',
calculate: function (value) {
return value.toUpperCase() + ' ' + this.firstname;
}
},
todos: {
default: [
{text: 'b'},
{text: 'c'},
{text: 'a'}
],
calculate: function () {
var self = this;
return this.todos.map(function (todo) {
return {text: todo.text.toString().toUpperCase()};
});
}
}
},

@@ -21,3 +40,3 @@ initialize: function (todos) {

if (todos) {
this.todos = this.todos.concat(todos);
this.todos = this.set('todos', this.todos.concat(todos));
}

@@ -39,3 +58,3 @@

addTodo: function (todo) {
this.todos.push({text: todo.text});
this.set('todos', this.todos.concat({text: todo.text}));
},

@@ -49,3 +68,3 @@

this.todos = filteredData;
this.set('todos', filteredData);
this.emit('change');

@@ -55,12 +74,7 @@ },

resetTodos: function (todos) {
this.todos = todos;
this.set('todos', todos);
this.listenChanges(this.todos);
this.emit('change');
},
}
getState: function () {
return {
todos: this.todos
}
}
});

@@ -212,5 +226,6 @@

return <div>
<span>{this.dispatcher.getStore('todoStore').fullname}</span>
<TodoListView />
<TodoFormView />
<span>There are {this.stores.todoStore.store.todos.length} todos.</span>
<span>There are {this.dispatcher.getStore('todoStore').todos.length} todos.</span>
</div>

@@ -217,0 +232,0 @@ }

{
"name": "delorean.js",
"version": "0.7.2",
"version": "0.8.0",
"description": "Flux Library",

@@ -5,0 +5,0 @@ "main": "src/delorean.js",

@@ -5,3 +5,3 @@ # DeLorean.js

[![NPM version](https://badge.fury.io/js/delorean.js.svg)](http://badge.fury.io/js/delorean.js)
![Coverage](http://progressed.io/bar/82?title=coverage)
![Coverage](http://progressed.io/bar/84?title=coverage)

@@ -14,3 +14,3 @@ DeLorean is a tiny Flux pattern implementation.

- It's framework agnostic, completely. There's **no view framework dependency**.
- Very small, just **4K** gzipped.
- Very small, just **5K** gzipped.
- Built-in **React.js** integration, easy to use with **Flight.js** and **Ractive.js** and probably all others.

@@ -142,10 +142,2 @@ - Improve your UI/data consistency using **rollbacks**.

## Name
The **flux capacitor** was the core component of Doctor Emmett Brown's **DeLorean time machine**
## License
[MIT License](http://f.mit-license.org)
## Authors

@@ -162,1 +154,27 @@

- Fehmi Can Sağlam [@fehmicansaglam](https://github.com/fehmicansaglam)
## Contribution
```bash
git clone git@github.com:deloreanjs/delorean.git
cd delorean
git checkout -b your-feature-branch
```
After you make some changes and add your test cases to the `test/spec/*Spec.js`
files. please run:
```bash
grunt
grunt test
```
When it's all OK, [open a pull request](https://github.com/deloreanjs/delorean/compare/).
## License
[MIT License](http://f.mit-license.org)
## Name
The **flux capacitor** was the core component of Doctor Emmett Brown's **DeLorean time machine**

@@ -10,3 +10,3 @@ (function (DeLorean) {

// ## Global Helper Functions
// ## Private Helper Functions

@@ -16,3 +16,3 @@ // Helper functions are private functions to be used in codebase.

// `__hasOwn` function is a shortcut for `Object#hasOwnProperty`.
/* `__hasOwn` function is a shortcut for `Object#hasOwnProperty` */
function __hasOwn(object, prop) {

@@ -29,6 +29,12 @@ return Object.prototype.hasOwnProperty.call(object, prop);

/* It's used by the schemes to save the original version (not calculated)
of the data. */
function __generateOriginalName(name) {
return 'original:' + name;
}
// `__findDispatcher` is a private function for **React components**.
// `view` should be a component instance. If a component don't have
// any dispatcher, it tries to find a dispatcher from the parents.
function __findDispatcher(view) {
/* `view` should be a component instance. If a component don't have
any dispatcher, it tries to find a dispatcher from the parents. */
if (!view.props.dispatcher) {

@@ -52,4 +58,3 @@ return __findDispatcher(view._owner);

// Rollback listener adds a `rollback` event listener to the bunch of
// stores. If any of them fires `rollback` event, all of the stores
// will be emitted to be rolled back with `__rollback` event.
// stores.
function __rollbackListener(stores) {

@@ -63,2 +68,4 @@

/* If any of them fires `rollback` event, all of the stores
will be emitted to be rolled back with `__rollback` event. */
for (var j in stores) {

@@ -77,3 +84,3 @@ stores[j].listener.on('rollback', __listener);

// Stores should be listened for rollback events.
/* Stores should be listened for rollback events. */
__rollbackListener(Object.keys(stores).map(function (key) {

@@ -88,3 +95,3 @@ return stores[key];

// Stores are key-value pairs. Collect store instances into an array.
/* Stores are key-value pairs. Collect store instances into an array. */
stores = (function () {

@@ -94,3 +101,3 @@ var stores = [], store;

store = self.stores[storeName];
// Store value must be an _instance of Store_.
/* Store value must be an _instance of Store_. */
if (!store instanceof Store) {

@@ -108,3 +115,3 @@ throw 'Given store is not a store instance';

// Payload should send to all related stores.
/* Payload should send to all related stores. */
for (var storeName in self.stores) {

@@ -114,3 +121,4 @@ self.stores[storeName].dispatchAction(actionName, data);

// And so you can just use **promise** for dispatching: `dispatch(..).then(..)`.
// `dispatch` returns deferred object you can just use **promise**
// for dispatching: `dispatch(..).then(..)`.
return deferred;

@@ -128,4 +136,4 @@ };

// `__promiseGenerator` generates a simple promise that resolves itself when
// related store is changed.
/* `__promiseGenerator` generates a simple promise that resolves itself when
related store is changed. */
function __promiseGenerator(store) {

@@ -154,3 +162,3 @@ // `DeLorean.Promise` is `require('es6-promise').Promise` by default.

Dispatcher.prototype.registerAction = function (action, callback) {
// The callback must be a function.
/* The callback must be a function. */
if (typeof callback === 'function') {

@@ -202,3 +210,3 @@ this[action] = callback.bind(this.stores);

function Store(store, args) {
// store parameter must be an `object`
/* store parameter must be an `object` */
if (typeof store !== 'object') {

@@ -212,7 +220,9 @@ throw 'Stores should be defined by passing the definition to the constructor';

// Store is _hygenic_ object. DeLorean doesn't extend it, it uses it.
/* Store is _hygenic_ object. DeLorean doesn't extend it, it uses it. */
this.store = store;
this.bindActions();
this.buildScheme();
// `initialize` is the construction function.
// `initialize` is the construction function, you can define `initialize` method
// in your store definitions.
if (typeof store.initialize === 'function') {

@@ -223,2 +233,87 @@ store.initialize.apply(this.store, args);

Store.prototype.set = function (key, value) {
var scheme = this.store.scheme, definition;
if (scheme && this.store.scheme[key]) {
definition = scheme[key];
this.store[key] = value || definition.default;
if (typeof definition.calculate === 'function') {
this.store[__generateOriginalName(key)] = value;
this.store[key] = definition.calculate.call(this.store, value);
}
this.recalculate();
} else {
throw 'Scheme should include the key ' + key + ' you wanted to set.';
}
return this.store[key];
};
// Removes the scheme format and standardizes all the shortcuts.
// If you run `formatScheme({name: 'joe'})` it will return you
// `{name: {default: 'joe'}}`. Also if you run `formatScheme({fullname: function () {}})`
// it will return `{fullname: {calculate: function () {}}}`.
Store.prototype.formatScheme = function (scheme) {
var formattedScheme = {};
for (var keyName in scheme) {
var definition = scheme[keyName], defaultValue, calculatedValue;
formattedScheme[keyName] = {default: null};
/* {key: 'value'} will be {key: {default: 'value'}} */
defaultValue = (typeof definition === 'object') ?
definition.default : definition;
formattedScheme[keyName].default = defaultValue;
/* {key: function () {}} will be {key: {calculate: function () {}}} */
if (typeof definition.calculate === 'function') {
calculatedValue = definition.calculate;
} else if (typeof definition === 'function') {
calculatedValue = definition;
}
if (calculatedValue) {
formattedScheme[keyName].calculate = calculatedValue;
}
}
return formattedScheme;
};
/* Applying `scheme` to the store if exists. */
Store.prototype.buildScheme = function () {
var scheme, calculatedData, keyName, definition;
if (typeof this.store.scheme === 'object') {
/* Scheme must be formatted to standardize the keys. */
scheme = this.store.scheme = this.formatScheme(this.store.scheme);
/* Set the defaults first */
for (keyName in scheme) {
definition = scheme[keyName];
this.store[keyName] = definition.default;
}
/* Set the calculations */
for (keyName in scheme) {
definition = scheme[keyName];
if (definition.calculate) {
this.store[__generateOriginalName(keyName)] = definition.default;
this.store[keyName] = definition.calculate.call(this.store, definition.default);
}
}
}
};
Store.prototype.recalculate = function () {
var scheme = this.store.scheme, definition, keyName;
for (keyName in scheme) {
definition = scheme[keyName];
if (typeof definition.calculate === 'function') {
this.store[keyName] = definition.calculate.call(this.store,
this.store[__generateOriginalName(keyName)] || definition.default);
}
}
this.listener.emit('change');
};
// `bindActions` is semi-private method. You'll never need to call it from outside.

@@ -229,3 +324,4 @@ // It powers up the `this.store` object.

// Some required methods can be used in **store definition**.
// Some required methods can be used in **store definition** like
// **`emit`**, **`emitChange`**, **`emitRollback`**, **`rollback`**, **`listenChanges`**
this.store.emit = this.listener.emit.bind(this.listener);

@@ -236,6 +332,6 @@ this.store.emitChange = this.listener.emit.bind(this.listener, 'change');

this.store.listenChanges = this.listenChanges.bind(this);
this.store.set = this.set.bind(this);
// Stores must have a `actions` hash of `actionName: methodName`
// `methodName` is the `this.store`'s prototype method. And `actionName`
// should be a name generated by `__generateActionName`.
// `methodName` is the `this.store`'s prototype method..
for (var actionName in this.store.actions) {

@@ -247,2 +343,3 @@ if (__hasOwn(this.store.actions, actionName)) {

}
/* And `actionName` should be a name generated by `__generateActionName` */
this.listener.on(__generateActionName(actionName),

@@ -300,3 +397,3 @@ this.store[callback].bind(this.store));

// `createDispatcher` generates a dispatcher with actions to dispatch.
// `actionsToDispatch` should be an object.
/* `actionsToDispatch` should be an object. */
createDispatcher: function (actionsToDispatch) {

@@ -310,9 +407,9 @@ var actionsOfStores, dispatcher, callback;

// If there are no stores defined, it's an empty object.
/* If there are no stores defined, it's an empty object. */
dispatcher = new Dispatcher(actionsOfStores || {});
// Now call `registerAction` method for every action.
/* Now call `registerAction` method for every action. */
for (var actionName in actionsToDispatch) {
if (__hasOwn(actionsToDispatch, actionName)) {
// `getStores` is the special function, it's not an action.
/* `getStores` is the special function, it's not an action. */
if (actionName !== 'getStores') {

@@ -350,8 +447,7 @@ callback = actionsToDispatch[actionName];

// `__changeHandler` is a **listener generator** to pass to the `onChange`
// function.
/* `__changeHandler` is a **listener generator** to pass to the `onChange` function. */
function __changeHandler(store, storeName) {
return function () {
var state, args;
// Call the components `storeDidChanged` method if exists.
// When something changes it calls the components `storeDidChanged` method if exists.
if (self.storeDidChange) {

@@ -361,3 +457,3 @@ args = [storeName].concat(Array.prototype.slice.call(arguments, 0));

}
// If the component is mounted, change state.
/* If the component is mounted, change state. */
if (self.isMounted()) {

@@ -369,3 +465,3 @@ self.setState(self.getStoreStates());

// Generate and bind the change handlers to the stores.
/* Generate and bind the change handlers to the stores. */
for (var storeName in this.stores) {

@@ -379,3 +475,3 @@ if (__hasOwn(this.stores, storeName)) {

// When a component unmounted, it should stop listening. (TODO)
// When a component unmounted, it should stop listening.
componentWillUnmount: function () {

@@ -385,3 +481,3 @@ for (var storeName in this.stores) {

var store = this.stores[storeName];
// FIXME: What if another mounted view listening this store? Commenting out for now.
/* FIXME: What if another mounted view listening this store? Commenting out for now. */
store.listener.removeAllListeners('change');

@@ -395,4 +491,4 @@ }

// The dispatcher should be easy to access and it should use `__findDispatcher`
// method to find the parent dispatchers.
/* The dispatcher should be easy to access and it should use `__findDispatcher`
method to find the parent dispatchers. */
this.dispatcher = __findDispatcher(this);

@@ -409,2 +505,3 @@

// Since `dispatcher.stores` is harder to write, there's a shortcut for it.
// You can use `this.stores` from the React component.
this.stores = this.dispatcher.stores;

@@ -418,3 +515,3 @@

// Set `state.stores` for all present stores with a `setState` method defined.
/* Set `state.stores` for all present stores with a `setState` method defined. */
for (var storeName in this.stores) {

@@ -427,2 +524,7 @@ if (__hasOwn(this.stores, storeName)) {

state.stores[storeName] = this.stores[storeName].store.getState();
} else if (typeof this.stores[storeName].store.scheme === 'object') {
var scheme = this.stores[storeName].store.scheme;
for (var keyName in scheme) {
state.stores[storeName] = this.stores[storeName].store[keyName];
}
}

@@ -429,0 +531,0 @@ }

@@ -101,2 +101,29 @@ describe('Flux', function () {

myStoreWithScheme = new (DeLorean.Flux.createStore({
scheme: {
x: 'hello',
y: 'world',
z: function () {
return this.x + ', ' + this.y;
},
t: {
default: 'def',
calculate: function (value) {
return value.toUpperCase() + ' ' + this.z;
}
}
}
}));
it('should be work with schemes', function () {
expect(myStoreWithScheme.store.z).toBe('hello, world');
myStoreWithScheme.set('y', 'moon');
expect(myStoreWithScheme.store.z).toBe('hello, moon');
myStoreWithScheme.set('x', 'salut');
expect(myStoreWithScheme.store.z).toBe('salut, moon');
expect(myStoreWithScheme.store.t).toBe('DEF salut, moon');
myStoreWithScheme.set('t', 'hey');
expect(myStoreWithScheme.store.t).toBe('HEY salut, moon');
});
});

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 too big to display

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