@ngneat/elf
Advanced tools
Comparing version 2.3.0 to 2.3.1
72
index.js
@@ -9,3 +9,2 @@ import { BehaviorSubject, Subject, Observable, pipe, asapScheduler } from 'rxjs'; | ||
}; | ||
for (const { | ||
@@ -18,3 +17,2 @@ config, | ||
} | ||
return result; | ||
@@ -32,3 +30,2 @@ } | ||
} | ||
return cb(); | ||
@@ -39,3 +36,2 @@ } | ||
const elfHooksRegistry = {}; | ||
class ElfHooks { | ||
@@ -45,9 +41,6 @@ registerPreStoreUpdate(fn) { | ||
} | ||
registerPreStateInit(fn) { | ||
elfHooksRegistry.preStateInit = fn; | ||
} | ||
} | ||
const elfHooks = new ElfHooks(); | ||
@@ -57,4 +50,4 @@ | ||
const registryActions = new Subject(); | ||
const registry$ = registryActions.asObservable(); // @internal | ||
const registry$ = registryActions.asObservable(); | ||
// @internal | ||
function addStore(store) { | ||
@@ -66,4 +59,4 @@ registry.set(store.name, store); | ||
}); | ||
} // @internal | ||
} | ||
// @internal | ||
function removeStore(store) { | ||
@@ -102,7 +95,5 @@ registry.delete(store.name); | ||
} | ||
get name() { | ||
return this.storeDef.name; | ||
} | ||
getInitialState(state) { | ||
@@ -112,14 +103,10 @@ if (elfHooksRegistry.preStateInit) { | ||
} | ||
return state; | ||
} | ||
getConfig() { | ||
return this.storeDef.config; | ||
} | ||
query(selector) { | ||
return selector(this.getValue()); | ||
} | ||
update(...reducers) { | ||
@@ -131,10 +118,7 @@ const currentState = this.getValue(); | ||
}, currentState); | ||
if (elfHooksRegistry.preStoreUpdate) { | ||
nextState = elfHooksRegistry.preStoreUpdate(currentState, nextState, this.name); | ||
} | ||
if (nextState !== currentState) { | ||
this.state = nextState; | ||
if (batchInProgress.getValue()) { | ||
@@ -153,11 +137,8 @@ if (!this.batchInProgress) { | ||
} | ||
getValue() { | ||
return this.state; | ||
} | ||
reset() { | ||
this.update(() => this.initialState); | ||
} | ||
combine(observables) { | ||
@@ -173,3 +154,2 @@ let hasChange = true; | ||
} | ||
return this.subscribe({ | ||
@@ -182,15 +162,11 @@ next() { | ||
}, | ||
error(e) { | ||
observer.error(e); | ||
}, | ||
complete() { | ||
observer.complete(); | ||
} | ||
}); | ||
}); | ||
} | ||
destroy() { | ||
@@ -200,13 +176,9 @@ removeStore(this); | ||
} | ||
next(value) { | ||
this.update(() => value); | ||
} // eslint-disable-next-line @typescript-eslint/no-empty-function | ||
error() {} // eslint-disable-next-line @typescript-eslint/no-empty-function | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
error() {} | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
complete() {} | ||
} | ||
@@ -272,3 +244,2 @@ | ||
*/ | ||
function setProp(key, value) { | ||
@@ -300,3 +271,2 @@ return function (state) { | ||
*/ | ||
function setProps(props) { | ||
@@ -319,11 +289,9 @@ return function (state) { | ||
} | ||
if (prevCollection.length !== currentCollection.length) { | ||
return false; | ||
} | ||
const isOneOfItemReferenceChanged = currentCollection.some((item, i) => { | ||
return prevCollection[i] !== item; | ||
}); // return false means there is a change and we want to call next() | ||
}); | ||
// return false means there is a change and we want to call next() | ||
return !isOneOfItemReferenceChanged; | ||
@@ -352,15 +320,11 @@ }); | ||
}, | ||
[`set${normalizedKey}InitialValue`](value) { | ||
initialValue = value; | ||
}, | ||
[`set${normalizedKey}`](value) { | ||
return function (state) { | ||
const newVal = isFunction(value) ? value(state) : value; | ||
if (newVal === state[key]) { | ||
return state; | ||
} | ||
return Object.assign({}, state, { | ||
@@ -371,11 +335,8 @@ [key]: newVal | ||
}, | ||
[`update${normalizedKey}`](value) { | ||
return function (state) { | ||
const newVal = isFunction(value) ? value(state) : value; | ||
if (newVal === state[key]) { | ||
return state; | ||
} | ||
return Object.assign({}, state, { | ||
@@ -386,3 +347,2 @@ [key]: isObject(newVal) ? Object.assign({}, state[key], newVal) : newVal | ||
}, | ||
[`reset${normalizedKey}`]() { | ||
@@ -395,11 +355,8 @@ return function (state) { | ||
}, | ||
[`select${normalizedKey}`]() { | ||
return select(state => state[key]); | ||
}, | ||
[`get${normalizedKey}`](state) { | ||
return state[key]; | ||
} | ||
}; | ||
@@ -419,3 +376,2 @@ } | ||
}, | ||
[`remove${normalizedKey}`](items) { | ||
@@ -428,3 +384,2 @@ return function (state) { | ||
}, | ||
[`toggle${normalizedKey}`](items) { | ||
@@ -437,3 +392,2 @@ return function (state) { | ||
}, | ||
[`update${normalizedKey}`](predicateOrIds, obj) { | ||
@@ -446,7 +400,5 @@ return function (state) { | ||
}, | ||
[`in${normalizedKey}`](item) { | ||
return state => inArray(state[key], item); | ||
} | ||
}); | ||
@@ -489,4 +441,4 @@ } | ||
__DEV__ = false; | ||
} // @internal | ||
} | ||
// @internal | ||
function isDev() { | ||
@@ -493,0 +445,0 @@ return __DEV__; |
{ | ||
"name": "@ngneat/elf", | ||
"version": "2.3.0", | ||
"version": "2.3.1", | ||
"description": "A reactive state management for JS applications", | ||
@@ -32,3 +32,3 @@ "publishConfig": { | ||
"peerDependencies": { | ||
"typescript": ">= 4.1.2" | ||
"rxjs": ">=7.0.0" | ||
}, | ||
@@ -38,3 +38,3 @@ "module": "./index.js", | ||
"type": "module", | ||
"types": "./index.d.ts" | ||
"types": "./src/index.d.ts" | ||
} |
Sorry, the diff of this file is not supported yet
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
1035
36704