@stencil/store
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -116,5 +116,8 @@ 'use strict'; | ||
handlers[eventName].push(callback); | ||
return () => { | ||
removeFromArray(handlers[eventName], callback); | ||
}; | ||
}; | ||
const onChange = (propName, cb) => { | ||
on('set', (key, newValue) => { | ||
const unSet = on('set', (key, newValue) => { | ||
if (key === propName) { | ||
@@ -124,3 +127,7 @@ cb(newValue); | ||
}); | ||
on('reset', () => cb(defaultState[propName])); | ||
const unReset = on('reset', () => cb(defaultState[propName])); | ||
return () => { | ||
unSet(); | ||
unReset(); | ||
}; | ||
}; | ||
@@ -148,2 +155,9 @@ const use = (...subscriptions) => subscriptions.forEach((subscription) => { | ||
}; | ||
const removeFromArray = (array, item) => { | ||
const index = array.indexOf(item); | ||
if (index >= 0) { | ||
array[index] = array[array.length - 1]; | ||
array.length--; | ||
} | ||
}; | ||
@@ -150,0 +164,0 @@ const createStore = (defaultState) => { |
@@ -10,8 +10,8 @@ export interface Handlers<T> { | ||
export interface OnHandler<StoreType> { | ||
(eventName: 'set', callback: SetEventHandler<StoreType>): void; | ||
(eventName: 'get', callback: GetEventHandler<StoreType>): void; | ||
(eventName: 'reset', callback: ResetEventHandler): void; | ||
(eventName: 'set', callback: SetEventHandler<StoreType>): () => void; | ||
(eventName: 'get', callback: GetEventHandler<StoreType>): () => void; | ||
(eventName: 'reset', callback: ResetEventHandler): () => void; | ||
} | ||
export interface OnChangeHandler<StoreType> { | ||
<Key extends keyof StoreType>(propName: Key, cb: (newValue: StoreType[Key]) => void): void; | ||
<Key extends keyof StoreType>(propName: Key, cb: (newValue: StoreType[Key]) => void): () => void; | ||
} | ||
@@ -18,0 +18,0 @@ export interface Subscription<StoreType> { |
{ | ||
"name": "@stencil/store", | ||
"version": "1.0.1", | ||
"version": "1.1.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", |
Sorry, the diff of this file is not supported yet
17608
413