Comparing version 0.0.5 to 1.0.0
{ | ||
"name": "statecore", | ||
"version": "0.0.5", | ||
"version": "1.0.0", | ||
"description": "A state-observable library.", | ||
@@ -5,0 +5,0 @@ "main": "statecore.js", |
@@ -14,3 +14,3 @@ # statecore | ||
### StateCore.<strong>createStateCore([defaultValue])</strong> | ||
### statecore.<strong>createStatecore([defaultValue])</strong> | ||
@@ -20,13 +20,13 @@ Create a core object | ||
```JavaScript | ||
var coreObject = StateCore.createStateCore(); | ||
var coreObject = statecore.createStatecore(); | ||
// or | ||
var coreObject = StateCore.createStateCore('default value'); | ||
var coreObject = statecore.createStatecore('default value'); | ||
``` | ||
---------- | ||
### coreObject.<strong>setState(newState)</strong> => newState | ||
### coreObject.<strong>getState()</strong> => any | ||
### coreObject.<strong>addObserver(observer)</strong> => removeObserver() | ||
### coreObject.<strong>notifyAllObservers(args1, arg2, ..., argN)</strong> => void | ||
### coreObject.<strong>discard()</strong> => void | ||
### coreObject.<strong>isDiscarded()</strong> =>Boolean | ||
### coreObject.<strong>statecoreSetState(newState)</strong> => newState | ||
### coreObject.<strong>statecoreGetState()</strong> => any | ||
### coreObject.<strong>statecoreAddObserver(observer)</strong> => removeObserver() | ||
### coreObject.<strong>statecoreNotifyAllObservers(args1, arg2, ..., argN)</strong> => void | ||
### coreObject.<strong>statecoreDiscard()</strong> => void | ||
### coreObject.<strong>statecoreIsDiscarded()</strong> =>Boolean |
@@ -1,20 +0,26 @@ | ||
'use strict'; | ||
(function (root, factory) { | ||
if (typeof define === 'function' && define.amd) { define('statecore', [], factory); define('StateCore', [], factory); } | ||
if (typeof exports === 'object') module.exports = factory(); | ||
if (!!root && typeof root === 'object') { root.statecore = root.StateCore = factory(); } | ||
})(typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : this, function () { | ||
return { createStateCore: function createStateCore(state) { | ||
(function modelify(rootProvider, name, deps, factory) { | ||
'use strict'; | ||
if (typeof define === 'function' && define.amd) return name ? define(name, deps, factory) : define(deps, factory); | ||
if (typeof exports === 'object') return module.exports = factory.apply(this, deps.map(dep => require(dep))); | ||
const root = (typeof rootProvider === 'function' ? rootProvider() : rootProvider); | ||
if (!root || typeof root !== 'object') throw new Error('Invalid root object!'); | ||
const model = factory.apply(this, deps.map(dep => root[dep])); | ||
if (name) return root[name] = model; | ||
})(function rootProvider() { | ||
return (typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : typeof global !== 'undefined' ? global : this); | ||
}, 'statecore', [], function def () { | ||
'use strict'; | ||
return { createStatecore: function createStatecore(state) { | ||
var undefined = (function _undefined() {})(); | ||
var allObservers = []; | ||
function discard() { state = undefined; allObservers = undefined; } | ||
function isDiscarded() { return allObservers === undefined; } | ||
function getState() { return state; } | ||
function setState(newState) { | ||
if (isDiscarded()) throw new Error('This StateCore has been discarded!'); | ||
function statecoreDiscard() { state = undefined; allObservers = undefined; } | ||
function statecoreIsDiscarded() { return allObservers === undefined; } | ||
function statecoreGetState() { return state; } | ||
function statecoreSetState(newState) { | ||
if (statecoreIsDiscarded()) throw new Error('This Statecore has been discarded!'); | ||
state = newState; | ||
return state; | ||
} | ||
function addObserver(observer) { | ||
if (isDiscarded()) throw new Error('This StateCore has been discarded!'); | ||
function statecoreAddObserver(observer) { | ||
if (statecoreIsDiscarded()) throw new Error('This Statecore has been discarded!'); | ||
allObservers.push(observer); | ||
@@ -26,8 +32,8 @@ return function removeObserver() { | ||
} | ||
function notifyAllObservers() { | ||
if (isDiscarded()) throw new Error('This StateCore has been discarded!'); | ||
function statecoreNotifyAllObservers() { | ||
if (statecoreIsDiscarded()) throw new Error('This Statecore has been discarded!'); | ||
for (var idx = 0; idx < allObservers.length; idx += 1) allObservers[idx].apply(this, arguments); | ||
} | ||
return { getState: getState, setState: setState, addObserver: addObserver, notifyAllObservers: notifyAllObservers, discard: discard, isDiscarded: isDiscarded }; | ||
return { statecoreGetState: statecoreGetState, statecoreSetState: statecoreSetState, statecoreAddObserver: statecoreAddObserver, statecoreNotifyAllObservers: statecoreNotifyAllObservers, statecoreDiscard: statecoreDiscard, statecoreIsDiscarded: statecoreIsDiscarded }; | ||
}}; | ||
}); |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
4648
38
1
1