@stencil/store
Advanced tools
Comparing version 1.4.1 to 1.5.0-0
@@ -44,11 +44,12 @@ 'use strict'; | ||
}, 2000); | ||
const stencilSubscription = ({ on }) => { | ||
const elmsToUpdate = new Map(); | ||
if (typeof core.getRenderingRef === 'function') { | ||
const stencilSubscription = () => { | ||
if (typeof core.getRenderingRef !== 'function') { | ||
// If we are not in a stencil project, we do nothing. | ||
// This function is not really exported by @stencil/core. | ||
on('dispose', () => { | ||
elmsToUpdate.clear(); | ||
}); | ||
on('get', (propName) => { | ||
return {}; | ||
} | ||
const elmsToUpdate = new Map(); | ||
return { | ||
dispose: () => elmsToUpdate.clear(), | ||
get: (propName) => { | ||
const elm = core.getRenderingRef(); | ||
@@ -58,4 +59,4 @@ if (elm) { | ||
} | ||
}); | ||
on('set', (propName) => { | ||
}, | ||
set: (propName) => { | ||
const elements = elmsToUpdate.get(propName); | ||
@@ -66,8 +67,8 @@ if (elements) { | ||
cleanupElements(elmsToUpdate); | ||
}); | ||
on('reset', () => { | ||
}, | ||
reset: () => { | ||
elmsToUpdate.forEach((elms) => elms.forEach(core.forceUpdate)); | ||
cleanupElements(elmsToUpdate); | ||
}); | ||
} | ||
}, | ||
}; | ||
}; | ||
@@ -145,13 +146,20 @@ | ||
}; | ||
const use = (...subscriptions) => subscriptions.forEach((subscription) => { | ||
if (subscription.set) { | ||
on('set', subscription.set); | ||
} | ||
if (subscription.get) { | ||
on('get', subscription.get); | ||
} | ||
if (subscription.reset) { | ||
on('reset', subscription.reset); | ||
} | ||
}); | ||
const use = (...subscriptions) => { | ||
const unsubs = subscriptions.reduce((unsubs, subscription) => { | ||
if (subscription.set) { | ||
unsubs.push(on('set', subscription.set)); | ||
} | ||
if (subscription.get) { | ||
unsubs.push(on('get', subscription.get)); | ||
} | ||
if (subscription.reset) { | ||
unsubs.push(on('reset', subscription.reset)); | ||
} | ||
if (subscription.dispose) { | ||
unsubs.push(on('dispose', subscription.dispose)); | ||
} | ||
return unsubs; | ||
}, []); | ||
return () => unsubs.forEach((unsub) => unsub()); | ||
}; | ||
const forceUpdate = (key) => { | ||
@@ -183,3 +191,3 @@ const oldValue = states.get(key); | ||
const map = createObservableMap(defaultState, shouldUpdate); | ||
stencilSubscription(map); | ||
map.use(stencilSubscription()); | ||
return map; | ||
@@ -186,0 +194,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
import { ObservableMap } from '../types'; | ||
export declare const stencilSubscription: <T>({ on }: ObservableMap<T>) => void; | ||
import { Subscription } from '../types'; | ||
export declare const stencilSubscription: <T>() => Subscription<T>; |
@@ -21,2 +21,3 @@ export interface Handlers<T> { | ||
export interface Subscription<StoreType> { | ||
dispose?(): void; | ||
get?<KeyFromStoreType extends keyof StoreType>(key: KeyFromStoreType): void; | ||
@@ -92,3 +93,3 @@ set?<KeyFromStoreType extends keyof StoreType>(key: KeyFromStoreType, newValue: StoreType[KeyFromStoreType], oldValue: StoreType[KeyFromStoreType]): void; | ||
*/ | ||
use(...plugins: Subscription<T>[]): void; | ||
use(...plugins: Subscription<T>[]): () => void; | ||
/** | ||
@@ -95,0 +96,0 @@ * Force a rerender of the specified key, just like the value changed. |
{ | ||
"name": "@stencil/store", | ||
"version": "1.4.1", | ||
"version": "1.5.0-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.", | ||
@@ -29,4 +29,5 @@ "main": "dist/index.js", | ||
], | ||
"author": "Manu Mtz.-Almeida", | ||
"author": "Ionic Team", | ||
"license": "MIT", | ||
"homepage": "https://stenciljs.com/docs/stencil-store", | ||
"peerDependencies": { | ||
@@ -36,10 +37,10 @@ "@stencil/core": ">=1.9.0" | ||
"devDependencies": { | ||
"@stencil/core": "2.4.0", | ||
"@types/jest": "^24.9.1", | ||
"jest": "26.6.3", | ||
"jest-cli": "26.6.3", | ||
"@stencil/core": "^2.8.0", | ||
"@types/jest": "^26", | ||
"jest": "^26", | ||
"jest-cli": "^26", | ||
"np": "^7.4.0", | ||
"prettier": "^2.2.1", | ||
"rollup": "^2.39.0", | ||
"ts-jest": "^26.5.1", | ||
"ts-jest": "^26", | ||
"typescript": "^4.1.5" | ||
@@ -49,4 +50,4 @@ }, | ||
"type": "git", | ||
"url": "git://github.com/manucorporat/stencil-store.git" | ||
"url": "git://github.com/ionic-team/stencil-store.git" | ||
} | ||
} |
@@ -96,3 +96,3 @@ # @stencil/store | ||
The state object is proxied, i. e. you can directly get and set properties and Store will automatically take care of component re-rendering when the state object is changed. | ||
The state object is proxied, i. e. you can directly get and set properties. If you access the state object in the `render` function of your component, Store will automatically re-render it when the state object is changed. | ||
@@ -99,0 +99,0 @@ Note: [`Proxy`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) objects are not supported by IE11 (not even with a polyfill), so you need to use the `store.get` and `store.set` methods of the API if you wish to support IE11. |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
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
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
21058
479
1