Comparing version 1.0.0 to 1.1.0
{ | ||
"name": "delux", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Beautiful, light and simple state manager inspired by Redux", | ||
"main": "index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:aniddan/delux.git" | ||
}, | ||
"keywords": [ | ||
"state", | ||
"manager", | ||
"immutable", | ||
"redux", | ||
"flux" | ||
], | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "node test.js" | ||
}, | ||
"author": "Iddan Aharonson", | ||
"author": "Iddan Aharonson <mail@iddan.co> (http://iddan.co)", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/aniddan/delux/issues" | ||
}, | ||
"homepage": "https://github.com/aniddan/delux", | ||
"dependencies": { | ||
"es6-promise": "" | ||
"es6-promise": "3.2.1", | ||
"proxy-polyfill": "^0.1.6" | ||
} | ||
} |
<h1> | ||
<img | ||
src="https://raw.githubusercontent.com/aniddan/delux/master/assets/delux.svg" | ||
style="height: 2em; margin-right: 5px;" | ||
src="https://cdn.rawgit.com/aniddan/delux/master/assets/delux.svg" | ||
height="32" | ||
/> | ||
@@ -15,14 +15,16 @@ Delux | ||
let store = new Store (); | ||
store.tasks = new Store.Collection ({tasks: []}); | ||
store.on('addTask', (action, state) => state.tasks.push(action.payload)); | ||
store.tasks.on('addTask', (action, state) => state.push({ | ||
name: action.payload, | ||
completed: false | ||
})); | ||
store.observe('tasks', state => console.log(state)); | ||
store.observe('tasks', (state) => console.log(state.tasks)); | ||
store.dispatch({ | ||
type: 'addTask', | ||
payload: { | ||
name: 'Try Redux' | ||
} | ||
}) | ||
payload: 'Try Redux' | ||
}); | ||
@@ -56,6 +58,14 @@ ``` | ||
#### Store instances methods | ||
#### Store instances | ||
##### Store.prototype.dispatch() | ||
##### Properties | ||
###### Store.prototype.state | ||
Returns an object with mutations of the collections' states | ||
##### Methods | ||
###### Store.prototype.dispatch() | ||
Dispatches a [Flux Standard Action][FSA] on the state | ||
@@ -72,3 +82,3 @@ | ||
##### Store.prototype.observe() | ||
###### Store.prototype.observe() | ||
@@ -85,3 +95,3 @@ Adds an observer for mutations in the store's collections | ||
- **collectionNames** - array of collection names to observe their state mutation | ||
- **names | name** - array of collection names or a single name to observe for state mutation | ||
- **observer** - a function that with a given state mutation receives the name of the changed collection and it's new state. The arguments to the function are as follows: | ||
@@ -91,4 +101,3 @@ | ||
|------------|----------------------------- | | ||
| name | The changed collection name | | ||
| state | The changed collection state | | ||
| state | Store.prototype.state alias | | ||
@@ -149,3 +158,3 @@ ##### Store.prototype.use() | ||
- **types** - array of action types to apply the reducer on | ||
- **types | type** - array of action types or a single type to apply the reducer on | ||
- **reducer** - a function that with a given action mutates the collection state. The arguments to the function are as follows: | ||
@@ -159,2 +168,3 @@ | ||
[Delux Logo]: https://cdn.rawgit.com/aniddan/delux/master/assets/delux.svg | ||
[Immutability in JavaScript]: https://www.sitepoint.com/immutability-javascript/ | ||
@@ -161,0 +171,0 @@ [FSA]: https://github.com/acdlite/flux-standard-action |
const ArrayTree = require('./arraytree'); | ||
const validateArray = require('./validate-array'); | ||
@@ -9,3 +10,3 @@ module.exports = class Collection { | ||
on: {value: (types, reducer) => { | ||
reducers.set(types, reducer); | ||
reducers.set(validateArray(types), reducer); | ||
return this; | ||
@@ -12,0 +13,0 @@ }}, |
const Collection = require('./collection'); | ||
const ArrayTree = require('./arraytree'); | ||
const validateArray = require('./validate-array'); | ||
@@ -13,14 +14,40 @@ module.exports = class Store { | ||
}, | ||
use: {value: (middleware) => { | ||
middlewares.push(middleware); | ||
return this; | ||
}}, | ||
observe: {value: (collections, observer) => { | ||
observers.set(collections, observer); | ||
return this; | ||
}}, | ||
middlewares: {get: () => Object.assign([], middlewares)}, | ||
observers: {get: () => ArrayTree.toImmutable(observers)} | ||
middlewares: { | ||
get: () => Object.assign([], middlewares) | ||
}, | ||
observers: { | ||
get: () => ArrayTree.toImmutable(observers) | ||
}, | ||
use: { | ||
value: (middleware) => { | ||
middlewares.push(middleware); | ||
return this; | ||
} | ||
}, | ||
observe: { | ||
value: (collections, observer) => { | ||
observers.set(validateArray(collections), observer); | ||
return this; | ||
} | ||
} | ||
}); | ||
} | ||
get state () { | ||
let state = {}; | ||
for (let key in this) { | ||
Object.defineProperty(state, key, { | ||
get: () => { | ||
let value = this[key]; | ||
if (value instanceof Collection) { | ||
return value.state; | ||
} | ||
else { | ||
return value; | ||
} | ||
}, | ||
enumerable: true | ||
}); | ||
} | ||
return state; | ||
} | ||
dispatch (action) { | ||
@@ -32,4 +59,4 @@ this.queue = this.queue.then(applyMiddlewares.bind(this, action)) | ||
if (collection instanceof Collection) { | ||
let {state} = collection; | ||
let reducer = collection.reducers.get(action.type); | ||
let {state, reducers} = collection; | ||
let reducer = reducers.get(action.type); | ||
if (reducer) { | ||
@@ -39,3 +66,3 @@ Promise.resolve(reducer.call(this, action, state)) | ||
for (let observer of this.observers.get(collection_name)) { | ||
observer(collection_name, state); | ||
observer(this.state); | ||
} | ||
@@ -42,0 +69,0 @@ }); |
@@ -26,3 +26,3 @@ const Store = require('.'); | ||
// MIDDLEWARES ACCURE SYNCRONIOUSLY | ||
// MIDDLEWARES ACCURE IN ORDER | ||
@@ -36,3 +36,3 @@ store.use(action => { | ||
// gets state from a getter | ||
store.images.on(['getAllImages'], (action, state) => { | ||
store.images.on('getAllImages', (action, state) => { | ||
for (let image of action.payload.response) { | ||
@@ -51,3 +51,4 @@ state[image.id] = image; | ||
// React anybody? | ||
store.observe(['images'], console.log); | ||
store.observe('images', (state) => console.log(state.images)); | ||
store.observe(['images'], (state) => console.log(state.images)); | ||
@@ -54,0 +55,0 @@ // flux actions, so pretty |
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
13098
11
198
1
0
1
171
0
1
2
+ Addedproxy-polyfill@^0.1.6
+ Addedes6-promise@3.2.1(transitive)
+ Addedproxy-polyfill@0.1.7(transitive)
- Removedes6-promise@4.2.8(transitive)
Updatedes6-promise@3.2.1