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 0.0.2 to 1.0.0

.npmignore

86

index.js

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

let states = [{}];
Object.defineProperty(states, 'last', {
get () {
return this[this.length - 1];
}
});
module.exports = class Store {
constructor () {
Object.assign(this, {
queue: Promise.resolve(),
reducers: [],
listeners: [],
middlewares: []
});
}
get state () {
states.push(Object.assign({}, states.last));
return states.last;
}
use (middleware) {
this.middlewares.push(middleware);
}
listen (types, listener) {
this.listeners.push(Object.assign(listener, {
types: prepareTypes(types)
}));
}
attach (types, reducer) {
this.reducers.push(Object.assign(reducer, {
types: prepareTypes(types)
}));
}
dispatch (type, action = {}) {
let chain = Promise.resolve(action)
.then(alter.bind(this))
.catch(err => err)
.then(reduce(type, this.reducers, this.state));
notify.call(this, type, chain);
}
};
function alter (action) {
let alter_chain = Promise.resolve(action);
for (let middleware of this.middlewares) {
alter_chain = alter_chain.then(action => middleware(action));
}
return alter_chain;
}
function reduce (type, reducers, state) {
return function (action) {
let reducer_chain = Promise.resolve();
for (let reducer of reducers) {
if (reducer.types.includes(type)) {
reducer_chain = reducer_chain.then(reducer(state, action));
}
}
reducer_chain = reducer_chain.then(() => action);
return reducer_chain;
};
}
function notify (type, chain) {
this.queue
.then(() => chain)
.then(action => {
for (let listener of this.listeners) {
if (listener.types.includes(type)) {
listener(this.state, action);
}
}
});
}
function prepareTypes (types) {
if (typeof types == 'string') {
types = [types];
}
else if (!Array.isArray(types)) {
throw new Error ('types must be an array or a string');
}
return types;
}
require('es6-promise').polyfill();
module.exports = require('./src/store');
{
"name": "delux",
"version": "0.0.2",
"description": "Simplified combinition of Flux Redux",
"version": "1.0.0",
"description": "Beautiful, light and simple state manager inspired by Redux",
"main": "index.js",

@@ -11,3 +11,5 @@ "scripts": {

"license": "MIT",
"dependencies": {}
"dependencies": {
"es6-promise": ""
}
}
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