Socket
Socket
Sign inDemoInstall

@stencil/store

Package Overview
Dependencies
Maintainers
11
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stencil/store - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

8

dist/index.js

@@ -72,3 +72,3 @@ 'use strict';

const createObservableMap = (defaultState) => {
const createObservableMap = (defaultState, shouldUpdate = (a, b) => a !== b) => {
let states = new Map(Object.entries(defaultState !== null && defaultState !== void 0 ? defaultState : {}));

@@ -97,3 +97,3 @@ const handlers = {

const oldValue = states.get(propName);
if (oldValue !== value || typeof value === 'object') {
if (shouldUpdate(value, oldValue, propName)) {
states.set(propName, value);

@@ -174,4 +174,4 @@ handlers.set.forEach((cb) => cb(propName, value, oldValue));

const createStore = (defaultState) => {
const map = createObservableMap(defaultState);
const createStore = (defaultState, shouldUpdate) => {
const map = createObservableMap(defaultState, shouldUpdate);
stencilSubscription(map);

@@ -178,0 +178,0 @@ return map;

import { ObservableMap } from './types';
export declare const createObservableMap: <T extends {
[key: string]: any;
}>(defaultState?: T) => ObservableMap<T>;
}>(defaultState?: T, shouldUpdate?: (newV: any, oldValue: any, prop: keyof T) => boolean) => ObservableMap<T>;
import { ObservableMap } from './types';
export declare const createStore: <T extends {
[key: string]: any;
}>(defaultState?: T) => ObservableMap<T>;
}>(defaultState?: T, shouldUpdate?: (newV: any, oldValue: any, prop: keyof T) => boolean) => ObservableMap<T>;
{
"name": "@stencil/store",
"version": "1.2.0",
"version": "1.3.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",

@@ -80,6 +80,14 @@ # @stencil/store

### `createStore<T>(initialState)`
### `createStore<T>(initialState?: T, shouldUpdate?)`
Create a new store with the given initial state. The type is inferred from `initialState`, or can be passed as the generic type `T`.
By default, store performs a exact comparison (`===`) between the new value, and the previous one in order to prevent unnecessary rerenders, however, this behaviour can be changed by providing a `shouldUpdate` function through the second argument. When this function returns `false`, the value won't be updated. By providing a custom `shouldUpdate()` function, applications can create their own fine-grained change detection logic, beyond the default `===`. This may be useful for certain use-cases to avoid any expensive re-rendering.
```ts
const shouldUpdate = (newValue, oldValue, propChanged) => {
return JSON.stringify(newValue) !== JSON.stringify(oldValue);
}
```
Returns a `store` object with the following properties.

@@ -86,0 +94,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc