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.2.0 to 1.3.0

bin/index.js

88

package.json
{
"name": "delux",
"version": "1.2.0",
"description": "Beautiful, light and simple state manager inspired by Redux",
"main": "src/index.js",
"repository": {
"type": "git",
"url": "git@github.com:aniddan/delux.git"
},
"keywords": [
"state",
"manager",
"immutable",
"redux",
"flux"
],
"scripts": {
"start": "webpack --watch",
"build": "webpack",
"test": "npm build && node test"
},
"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": "3.2.1"
},
"devDependencies": {
"babel-core": "^6.14.0",
"babel-loader": "^6.2.5",
"babel-preset-es2015": "^6.14.0",
"babel-preset-stage-0": "^6.5.0",
"webpack": "^1.13.2"
},
"babel": {
"presets": [
"es2015",
"stage-0"
]
}
"name": "delux",
"version": "1.3.0",
"description": "Beautiful, light and simple state manager inspired by Redux",
"main": "bin/index.js",
"repository": {
"type": "git",
"url": "git@github.com:aniddan/delux.git"
},
"keywords": [
"state",
"manager",
"immutable",
"redux",
"flux"
],
"scripts": {
"start": "webpack --progress --watch",
"build": "webpack --progress",
"test": "jest"
},
"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": "3.2.1"
},
"devDependencies": {
"babel-core": "^6.14.0",
"babel-loader": "^6.2.5",
"babel-preset-es2015": "^6.14.0",
"babel-preset-stage-0": "^6.5.0",
"jest": "^16.0.0",
"webpack": "^2.1.0-beta.25"
},
"babel": {
"presets": [
"es2015",
"stage-0"
]
},
"jest": {
"testEnvironment": "node"
}
}

@@ -84,2 +84,6 @@ <h1>

**Returns**
The mutated store state
###### Store.prototype.observe()

@@ -126,2 +130,10 @@

##### Store.prototype.state.get()
Get specific collection's state from the store's state
```JavaScript
let partialState = store.state.get(collectionNames);
```
###### Parameters

@@ -128,0 +140,0 @@

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

import {ensureArray} from './utils';
const {forceArray} = require('./utils');
export default class Collection {
module.exports = class Collection {
reducers = {};

@@ -10,7 +10,6 @@ observers = [];

on (types, reducer) {
types = ensureArray(types);
for (let type of types) {
for (let type of forceArray(types)) {
this.reducers[type] = reducer;
}
}
}
};

@@ -1,7 +0,6 @@

import Store from './store';
import Collection from './collection';
const Store = require('./store');
const Collection = require('./collection');
require('es6-promise').polyfill();
Store.Collection = Collection;
module.exports = Store;
module.exports.Collection = Collection;

@@ -1,11 +0,24 @@

import Collection from './collection';
import {ensureArray} from './utils';
const Collection = require('./collection');
const {forceArray, getByKeys} = require('./utils');
export default class Store {
module.exports = class Store {
middlewares = [];
queued = Promise.resolve();
state = {};
state = {
get (collections) {
return getByKeys(this, collections);
}
};
/**
* Append middleware
* @param {function} middleware
*/
use (middleware) {
this.middlewares.push(middleware);
}
/**
* Dispatch an action
* @param {object} action
* @returns {Promise} - resolves after the store state mutate
*/
dispatch (action) {

@@ -15,29 +28,47 @@ for (let middleware of this.middlewares) {

}
this.queue(() => {
for (let name in this) {
let collection = this[name];
if (collection instanceof Collection) {
let oldState = collection.state;
Promise.resolve(collection.reducers[action.type](oldState, action))
.then((newState = oldState) => {
if (newState !== oldState) {
collection.state = newState;
return this.queue(() =>
Promise.all(
Object.keys(this)
.filter(name =>
this[name] instanceof Collection &&
this[name].reducers[action.type]
)
.map(name => {
let collection = this[name];
let {state, reducers} = collection;
return Promise.resolve(reducers[action.type](state, action))
.then((newCollectionState = state) => {
if (newCollectionState !== state) {
collection.state = newCollectionState;
for (let observer of collection.observers) {
observer(Object.assign(this.state, {[name]: newState}), action, name);
observer(Object.assign(this.state, {
[name]: newCollectionState
}), action, name);
}
}
return newCollectionState;
});
}
}
});
})
)
.then(() => this.state)
);
}
/**
* Observe collections changes
* @param {string | array} collectionNames - collections to observe
* @param {function} observer
*/
observe (collectionNames, observer) {
collectionNames = ensureArray(collectionNames);
for (let name of collectionNames) {
for (let name of forceArray(collectionNames)) {
this[name].observers.push(observer);
}
}
queue (callback) {
this.queued = this.queued.then(callback);
/**
* Queue an action in the store's queue
* @param {function} action
* @returns {Promise} - resolves after the action resolves.
*/
queue (action) {
return this.queued = this.queued.then(action);
}
}
};

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

export let ensureArray = array => !array || Array.isArray(array) ? array : [array];
let forceArray = array => Array.isArray(array) ? array : [array];
function getByKeys (object, keys) {
let relevant = {};
for (let key of forceArray(keys)) {
relevant[key] = object[key];
}
return relevant;
}
module.exports = {forceArray, getByKeys};

@@ -1,4 +0,3 @@

const path = require('path');
module.exports = {
entry: './src/index.js',
module: {

@@ -8,2 +7,3 @@ loaders: [

test: /\.js$/,
include: /src/,
loader: 'babel'

@@ -13,13 +13,5 @@ },

},
resolve: {
root: [
path.resolve('./')
]
},
entry: {
'lib/index.js': './src/index.js',
},
output: {
path: '.',
filename: '[name]',
path: 'bin',
filename: 'index.js',
library: 'delux',

@@ -26,0 +18,0 @@ libraryTarget: 'umd',

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