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

delux

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

delux - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

LICENSE

24

package.json
{
"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"
}
}

40

readme.md
<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

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