Comparing version 0.7.0 to 0.8.0
@@ -22,2 +22,4 @@ !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.Alt=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){ | ||
var EE = Symbol("event emitter instance"); | ||
var INIT_SNAPSHOT = Symbol("init snapshot storage"); | ||
var LAST_SNAPSHOT = Symbol("last snapshot storage"); | ||
var LISTENERS = Symbol("stores action listeners storage"); | ||
@@ -27,3 +29,2 @@ var STATE_CONTAINER = VariableSymbol("the state container"); | ||
var STORE_SNAPSHOT = Symbol("event handler onTakeSnapshot"); | ||
var STORES_STORE = Symbol("stores storage"); | ||
@@ -174,5 +175,5 @@ var formatAsConstant = function (name) { | ||
Object.keys(obj).forEach(function (key) { | ||
Object.assign(instance[STORES_STORE][key][STATE_CONTAINER], obj[key]); | ||
if (instance[STORES_STORE][key][STORE_BOOTSTRAP]) { | ||
instance[STORES_STORE][key][STORE_BOOTSTRAP](); | ||
Object.assign(instance.stores[key][STATE_CONTAINER], obj[key]); | ||
if (instance.stores[key][STORE_BOOTSTRAP]) { | ||
instance.stores[key][STORE_BOOTSTRAP](); | ||
} | ||
@@ -183,7 +184,7 @@ }); | ||
var snapshot = function (instance) { | ||
return JSON.stringify(Object.keys(instance[STORES_STORE]).reduce(function (obj, key) { | ||
if (instance[STORES_STORE][key][STORE_SNAPSHOT]) { | ||
instance[STORES_STORE][key][STORE_SNAPSHOT](); | ||
return JSON.stringify(Object.keys(instance.stores).reduce(function (obj, key) { | ||
if (instance.stores[key][STORE_SNAPSHOT]) { | ||
instance.stores[key][STORE_SNAPSHOT](); | ||
} | ||
obj[key] = instance[STORES_STORE][key].getState(); | ||
obj[key] = instance.stores[key].getState(); | ||
return obj; | ||
@@ -193,6 +194,15 @@ }, {})); | ||
var saveInitialSnapshot = function (instance, key) { | ||
var state = instance.stores[key][STATE_CONTAINER]; | ||
var initial = JSON.parse(instance[INIT_SNAPSHOT]); | ||
initial[key] = state; | ||
instance[INIT_SNAPSHOT] = JSON.stringify(initial); | ||
}; | ||
var Alt = (function () { | ||
var Alt = function Alt() { | ||
this.dispatcher = new Dispatcher(); | ||
this[STORES_STORE] = {}; | ||
this.stores = {}; | ||
this[LAST_SNAPSHOT] = null; | ||
this[INIT_SNAPSHOT] = "{}"; | ||
}; | ||
@@ -215,3 +225,3 @@ | ||
getInstance: function () { | ||
return _this3[STORES_STORE][key]; | ||
return _this3.stores[key]; | ||
} | ||
@@ -222,7 +232,11 @@ }); | ||
if (this[STORES_STORE][key]) { | ||
if (this.stores[key]) { | ||
throw new ReferenceError("A store named " + key + " already exists, double check your store names or pass in\nyour own custom identifier for each store"); | ||
} | ||
return this[STORES_STORE][key] = Object.assign(new AltStore(this.dispatcher, store), getInternalMethods(StoreModel, builtIns)); | ||
this.stores[key] = Object.assign(new AltStore(this.dispatcher, store), getInternalMethods(StoreModel, builtIns)); | ||
saveInitialSnapshot(this, key); | ||
return this.stores[key]; | ||
}; | ||
@@ -273,3 +287,3 @@ | ||
var state = snapshot(this); | ||
this._lastSnapshot = state; | ||
this[LAST_SNAPSHOT] = state; | ||
return state; | ||
@@ -279,20 +293,20 @@ }; | ||
Alt.prototype.rollback = function () { | ||
bootstrap(this, this._lastSnapshot); | ||
bootstrap(this, this[LAST_SNAPSHOT]); | ||
}; | ||
Alt.prototype.bootstrap = function (data) { | ||
var _this5 = this; | ||
Alt.prototype.recycle = function () { | ||
bootstrap(this, this[INIT_SNAPSHOT]); | ||
}; | ||
Alt.prototype.flush = function () { | ||
var state = snapshot(this); | ||
this.recycle(); | ||
return state; | ||
}; | ||
if (typeof window === "undefined") { | ||
bootstrap(this, data); | ||
setTimeout(function () { | ||
return bootstrap(_this5, state); | ||
}); | ||
} else { | ||
bootstrap(this, data); | ||
this.bootstrap = function () { | ||
throw new ReferenceError("Stores have already been bootstrapped"); | ||
}; | ||
} | ||
Alt.prototype.bootstrap = function (data) { | ||
bootstrap(this, data); | ||
this.bootstrap = function () { | ||
throw new ReferenceError("Stores have already been bootstrapped"); | ||
}; | ||
}; | ||
@@ -299,0 +313,0 @@ |
{ | ||
"name": "alt", | ||
"version": "0.7.0", | ||
"version": "0.8.0", | ||
"description": "A flux implementation", | ||
@@ -14,3 +14,2 @@ "main": "dist/alt.js", | ||
"coveralls": "^2.11.2", | ||
"esnext": "^0.13.2", | ||
"istanbul": "^0.3.5", | ||
@@ -27,3 +26,3 @@ "sixpack": "^2.0.0" | ||
"coverage": "node ./node_modules/6to5/bin/6to5 src/alt.js > src/coverage-alt.js; node ./node_modules/6to5/bin/6to5 test.js > coverage-test.js; ./node_modules/istanbul/lib/cli.js cover coverage-test.js", | ||
"test": "node ./node_modules/6to5/bin/6to5 src/alt.js > src/coverage-alt.js; ./node_modules/6to5/bin/6to5-node test.js; ./node_modules/esnext/bin/esnext src/alt.js > src/coverage-alt.js; ./node_modules/6to5/bin/6to5-node test.js" | ||
"test": "node ./node_modules/6to5/bin/6to5 src/alt.js > src/coverage-alt.js; ./node_modules/6to5/bin/6to5-node test.js;" | ||
}, | ||
@@ -30,0 +29,0 @@ "keywords": [ |
# alt | ||
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/goatslacker/alt?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
> To alter. Altered; Changed. | ||
@@ -4,0 +6,0 @@ |
23
test.js
@@ -173,2 +173,4 @@ var Alt = require('./src/coverage-alt') | ||
assert.equal(typeof alt.stores.AltSecondStore, 'object', 'store exists in alt.stores') | ||
assert.equal(typeof myStore.externalMethod, 'function', 'static methods are made available') | ||
@@ -261,16 +263,5 @@ assert.equal(myStore.externalMethod(), true, 'static methods return proper result') | ||
// Store on server side bootstraps and then returns to previous state | ||
alt.bootstrap('{"MyStore":{"name":"elk"}}') | ||
assert.equal(myStore.getState().name, 'elk', 'temporary store state') | ||
setTimeout(() => { | ||
assert.equal(myStore.getState().name, 'badger', 'the state is reset to last state though') | ||
}) | ||
try { | ||
// Creating a global window object so we are in browser mode. | ||
global.window = {} | ||
// Attempting to bootstrap more than once | ||
alt.bootstrap('{}') | ||
alt.bootstrap('{"MyStore":{"name":"elk"}}') | ||
alt.bootstrap('{"MyStore":{"name":"bee"}}') | ||
@@ -465,2 +456,10 @@ assert.equal(true, false, 'I was able bootstrap more than once which is bad') | ||
}) | ||
alt.recycle() | ||
assert.equal(myStore.getState().name, 'first', 'recycle sets the state back to its origin') | ||
myActions.updateName('goat') | ||
var flushed = JSON.parse(alt.flush()) | ||
assert.equal(myStore.getState().name, 'first', 'flush is a lot like recycle') | ||
assert.equal(flushed.MyStore.name, 'goat', 'except that flush returns the state before recycling') | ||
}() |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4
634
68063
8
1228