electrum-store
Advanced tools
Comparing version 0.3.0 to 0.9.0
@@ -7,5 +7,5 @@ 'use strict'; | ||
var _node = require('./store/node.js'); | ||
var _state = require('./store/state.js'); | ||
var _node2 = _interopRequireDefault(_node); | ||
var _state2 = _interopRequireDefault(_state); | ||
@@ -24,5 +24,5 @@ var _store = require('./store/store.js'); | ||
Activity: _activity2.default, | ||
Node: _node2.default, | ||
State: _state2.default, | ||
Store: _store2.default, | ||
Theme: _theme2.default | ||
}; |
@@ -5,5 +5,5 @@ 'use strict'; | ||
var _node = require('./node.js'); | ||
var _state = require('./state.js'); | ||
var _node2 = _interopRequireDefault(_node); | ||
var _state2 = _interopRequireDefault(_state); | ||
@@ -16,5 +16,5 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function patchNode(store, node) { | ||
store._nodes[node.id] = node; | ||
return node; | ||
function patchState(store, state) { | ||
store._states[state.id] = state; | ||
return state; | ||
} | ||
@@ -26,9 +26,9 @@ | ||
function updateTree(store, node, mutation) { | ||
var parentId = _node2.default.getParentId(node.id); | ||
function updateTree(store, state, mutation) { | ||
var parentId = _state2.default.getParentId(state.id); | ||
if (parentId) { | ||
var parentNode = store.findNode(parentId) || _node2.default.create(parentId); | ||
updateTree(store, parentNode, mutation); | ||
var parentState = store.find(parentId) || _state2.default.create(parentId); | ||
updateTree(store, parentState, mutation); | ||
} | ||
return patchNode(store, _node2.default.with(node, mutation)); | ||
return patchState(store, _state2.default.with(state, mutation)); | ||
} | ||
@@ -47,6 +47,5 @@ | ||
} | ||
this._nodes = {}; | ||
this._states = {}; | ||
this._generation = 0; | ||
this._rootNode = _node2.default.createRootNode(this, values); | ||
this._rootState = _state2.default.createRootState(this, values); | ||
this._id = id; | ||
@@ -56,19 +55,22 @@ } | ||
_createClass(Store, [{ | ||
key: 'getNode', | ||
value: function getNode(id) { | ||
return this.findNode(id) || this.setNode(_node2.default.create(id)); | ||
key: 'select', | ||
value: function select(id) { | ||
if (arguments.length === 0) { | ||
return this._rootState; | ||
} | ||
return this.find(id) || this.setState(_state2.default.create(id)); | ||
} | ||
}, { | ||
key: 'setNode', | ||
value: function setNode(node) { | ||
if (typeof node === 'string') { | ||
node = _node2.default.create(node); | ||
key: 'setState', | ||
value: function setState(state) { | ||
if (typeof state === 'string') { | ||
state = _state2.default.create(state); | ||
} | ||
if (!node || !node.id || !(node instanceof _node2.default)) { | ||
throw new Error('Invalid node'); | ||
if (!state || !(state instanceof _state2.default)) { | ||
throw new Error('Invalid state'); | ||
} | ||
if (node === this.findNode(node.id)) { | ||
if (state === this.find(state.id)) { | ||
// No mutation | ||
return node; | ||
return state; | ||
} else { | ||
@@ -79,15 +81,18 @@ var mutation = { | ||
}; | ||
return updateTree(this, node, mutation); | ||
return updateTree(this, state, mutation); | ||
} | ||
} | ||
}, { | ||
key: 'findNode', | ||
value: function findNode(id) { | ||
key: 'find', | ||
value: function find(id) { | ||
if (arguments.length === 0) { | ||
return this._rootState; | ||
} | ||
if (typeof id !== 'string') { | ||
throw new Error('Invalid node id'); | ||
throw new Error('Invalid state id'); | ||
} | ||
if (id.length === 0) { | ||
return this._rootNode; | ||
return this._rootState; | ||
} else { | ||
return this._nodes[id]; | ||
return this._states[id]; | ||
} | ||
@@ -108,8 +113,8 @@ } | ||
get: function get() { | ||
return this._rootNode; | ||
return this._rootState; | ||
} | ||
}, { | ||
key: 'nodeCount', | ||
key: 'stateCount', | ||
get: function get() { | ||
return Object.keys(this._nodes).length; | ||
return Object.keys(this._states).length; | ||
} | ||
@@ -127,3 +132,3 @@ | ||
value: function link(props, id, override) { | ||
var node = props.node; | ||
var state = props.state; | ||
@@ -137,3 +142,3 @@ var theme = props.theme; | ||
return { | ||
node: node.getChild(id), | ||
state: state.select(id), | ||
theme: theme | ||
@@ -145,5 +150,5 @@ }; | ||
value: function read(props, id) { | ||
var node = props.node; | ||
var state = props.state; | ||
return node.getValue(id); | ||
return state.getValue(id); | ||
} | ||
@@ -150,0 +155,0 @@ }]); |
@@ -5,3 +5,3 @@ 'use strict'; | ||
var _electrumStore = require('electrum-store'); | ||
var _index = require('../index.js'); | ||
@@ -12,3 +12,3 @@ describe('Theme', function () { | ||
(0, _maiChai.expect)(function () { | ||
return new _electrumStore.Theme('x'); | ||
return new _index.Theme('x'); | ||
}).to.throw(Error); | ||
@@ -21,9 +21,9 @@ }); | ||
(0, _maiChai.expect)(function () { | ||
return _electrumStore.Theme.create(); | ||
return _index.Theme.create(); | ||
}).to.throw(Error); | ||
(0, _maiChai.expect)(function () { | ||
return _electrumStore.Theme.create(123); | ||
return _index.Theme.create(123); | ||
}).to.throw(Error); | ||
(0, _maiChai.expect)(function () { | ||
return _electrumStore.Theme.create(''); | ||
return _index.Theme.create(''); | ||
}).to.throw(Error); | ||
@@ -33,3 +33,3 @@ }); | ||
it('creates a Theme with initialized properties', function () { | ||
var theme = _electrumStore.Theme.create('default'); | ||
var theme = _index.Theme.create('default'); | ||
(0, _maiChai.expect)(theme.colors).to.have.property('red50'); | ||
@@ -36,0 +36,0 @@ (0, _maiChai.expect)(theme.palette).to.have.property('primary1Color'); |
{ | ||
"name": "electrum-store", | ||
"version": "0.3.0", | ||
"version": "0.9.0", | ||
"description": "Electrum store provides a store implementation tailored for Electrum.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
'use strict'; | ||
import Activity from './store/activity.js'; | ||
import Node from './store/node.js'; | ||
import State from './store/state.js'; | ||
import Store from './store/store.js'; | ||
@@ -10,5 +10,5 @@ import Theme from './store/theme.js'; | ||
Activity, | ||
Node, | ||
State, | ||
Store, | ||
Theme | ||
}; |
'use strict'; | ||
import Node from './node.js'; | ||
import State from './state.js'; | ||
/******************************************************************************/ | ||
function patchNode (store, node) { | ||
store._nodes[node.id] = node; | ||
return node; | ||
function patchState (store, state) { | ||
store._states[state.id] = state; | ||
return state; | ||
} | ||
@@ -16,9 +16,9 @@ | ||
function updateTree (store, node, mutation) { | ||
const parentId = Node.getParentId (node.id); | ||
function updateTree (store, state, mutation) { | ||
const parentId = State.getParentId (state.id); | ||
if (parentId) { | ||
const parentNode = store.findNode (parentId) || Node.create (parentId); | ||
updateTree (store, parentNode, mutation); | ||
const parentState = store.find (parentId) || State.create (parentId); | ||
updateTree (store, parentState, mutation); | ||
} | ||
return patchNode (store, Node.with (node, mutation)); | ||
return patchState (store, State.with (state, mutation)); | ||
} | ||
@@ -32,27 +32,29 @@ | ||
constructor (id, key, values) { | ||
if (key !== secretKey) { | ||
throw new Error ('Do not call Store constructor directly; use Store.create instead'); | ||
} | ||
this._nodes = {}; | ||
this._states = {}; | ||
this._generation = 0; | ||
this._rootNode = Node.createRootNode (this, values); | ||
this._rootState = State.createRootState (this, values); | ||
this._id = id; | ||
} | ||
getNode (id) { | ||
return this.findNode (id) || this.setNode (Node.create (id)); | ||
select (id) { | ||
if (arguments.length === 0) { | ||
return this._rootState; | ||
} | ||
return this.find (id) || | ||
this.setState (State.create (id)); | ||
} | ||
setNode (node) { | ||
if (typeof node === 'string') { | ||
node = Node.create (node); | ||
setState (state) { | ||
if (typeof state === 'string') { | ||
state = State.create (state); | ||
} | ||
if (!node || !node.id || !(node instanceof Node)) { | ||
throw new Error ('Invalid node'); | ||
if (!state || !(state instanceof State)) { | ||
throw new Error ('Invalid state'); | ||
} | ||
if (node === this.findNode (node.id)) { // No mutation | ||
return node; | ||
if (state === this.find (state.id)) { // No mutation | ||
return state; | ||
} else { | ||
@@ -63,14 +65,17 @@ const mutation = { | ||
}; | ||
return updateTree (this, node, mutation); | ||
return updateTree (this, state, mutation); | ||
} | ||
} | ||
findNode (id) { | ||
find (id) { | ||
if (arguments.length === 0) { | ||
return this._rootState; | ||
} | ||
if (typeof id !== 'string') { | ||
throw new Error ('Invalid node id'); | ||
throw new Error ('Invalid state id'); | ||
} | ||
if (id.length === 0) { | ||
return this._rootNode; | ||
return this._rootState; | ||
} else { | ||
return this._nodes[id]; | ||
return this._states[id]; | ||
} | ||
@@ -88,7 +93,7 @@ } | ||
get root () { | ||
return this._rootNode; | ||
return this._rootState; | ||
} | ||
get nodeCount () { | ||
return Object.keys (this._nodes).length; | ||
get stateCount () { | ||
return Object.keys (this._states).length; | ||
} | ||
@@ -103,3 +108,3 @@ | ||
static link (props, id, override) { | ||
const {node} = props; | ||
const {state} = props; | ||
let theme = props.theme; | ||
@@ -112,3 +117,3 @@ if (override) { | ||
return { | ||
node: node.getChild (id), | ||
state: state.select (id), | ||
theme | ||
@@ -119,4 +124,4 @@ }; | ||
static read (props, id) { | ||
const {node} = props; | ||
return node.getValue (id); | ||
const {state} = props; | ||
return state.getValue (id); | ||
} | ||
@@ -123,0 +128,0 @@ } |
'use strict'; | ||
import {expect} from 'mai-chai'; | ||
import {Theme} from 'electrum-store'; | ||
import {Theme} from '../index.js'; | ||
@@ -6,0 +6,0 @@ describe ('Theme', () => { |
@@ -13,3 +13,4 @@ /*globals __dirname */ | ||
{pattern: 'test/test-helper.js'}, | ||
{pattern: 'src/store/**/*.js'} | ||
{pattern: 'src/store/**/*.js'}, | ||
{pattern: 'src/*.js'} | ||
], | ||
@@ -16,0 +17,0 @@ tests: [ |
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
112262
55
3093