@stencil/store
Advanced tools
Comparing version 1.1.1 to 1.2.0
@@ -49,2 +49,5 @@ 'use strict'; | ||
// This function is not really exported by @stencil/core. | ||
on('dispose', () => { | ||
elmsToUpdate.clear(); | ||
}); | ||
on('get', (propName) => { | ||
@@ -73,2 +76,3 @@ const elm = core.getRenderingRef(); | ||
const handlers = { | ||
dispose: [], | ||
get: [], | ||
@@ -82,2 +86,8 @@ set: [], | ||
}; | ||
const dispose = () => { | ||
// Call first dispose as resetting the state would | ||
// cause less updates ;) | ||
handlers.dispose.forEach((cb) => cb()); | ||
reset(); | ||
}; | ||
const get = (propName) => { | ||
@@ -153,2 +163,3 @@ handlers.get.forEach((cb) => cb(propName)); | ||
use, | ||
dispose, | ||
reset, | ||
@@ -155,0 +166,0 @@ }; |
export interface Handlers<T> { | ||
set: SetEventHandler<T>[]; | ||
dispose: DisposeEventHandler[]; | ||
get: GetEventHandler<T>[]; | ||
reset: ResetEventHandler[]; | ||
set: SetEventHandler<T>[]; | ||
} | ||
@@ -9,5 +10,7 @@ export declare type SetEventHandler<StoreType> = (key: keyof StoreType, newValue: any, oldValue: any) => void; | ||
export declare type ResetEventHandler = () => void; | ||
export declare type DisposeEventHandler = () => void; | ||
export interface OnHandler<StoreType> { | ||
(eventName: 'set', callback: SetEventHandler<StoreType>): () => void; | ||
(eventName: 'get', callback: GetEventHandler<StoreType>): () => void; | ||
(eventName: 'dispose', callback: DisposeEventHandler): () => void; | ||
(eventName: 'reset', callback: ResetEventHandler): () => void; | ||
@@ -74,2 +77,10 @@ } | ||
/** | ||
* Resets the state to its original state and | ||
* signals a dispose event to all the plugins. | ||
* | ||
* This method is intended for plugins to reset | ||
* all their internal state between tests. | ||
*/ | ||
dispose(): void; | ||
/** | ||
* Resets the state to its original state. | ||
@@ -76,0 +87,0 @@ */ |
{ | ||
"name": "@stencil/store", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "Store is a lightweight shared state library by the StencilJS core team. Implements a simple key/value map that efficiently re-renders components when necessary.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -116,7 +116,11 @@ # @stencil/store | ||
#### `store.dispose()` | ||
Resets the store and all the internal state of the store that should not survive between tests. | ||
## Testing | ||
Like any global state library, state should be reset between each spec test. | ||
Use the `reset()` API in the `beforeEach` hook. | ||
Like any global state library, state should be `dispose`d between each spec test. | ||
Use the `dispose()` API in the `beforeEach` hook. | ||
@@ -127,4 +131,4 @@ ```ts | ||
beforeEach(() => { | ||
store.reset(); | ||
store.dispose(); | ||
}); | ||
``` |
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
18883
448
133