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 0.0.2 to 0.1.0

dist/observable-map.d.ts

12

dist/index.d.ts

@@ -1,8 +0,4 @@

export declare const createStore: <T extends {
[key: string]: any;
}>(defaultState?: T) => {
state: T;
get: <P extends keyof T>(state: P & string) => T[P];
set: <P_1 extends keyof T>(state: P_1 & string, value: T[P_1]) => void;
subscribe: (gen: (states: T) => void) => void;
};
export { createStore } from './store';
export { createObservableMap } from './observable-map';
export { computedSubscription } from './subscriptions/computed';
export { stencilSubscription } from './subscriptions/stencil';

@@ -1,69 +0,4 @@

// @ts-ignore
import { forceUpdate, getRenderingElement } from '@stencil/core';
// TODO
// reset()
export const createStore = (defaultState) => {
const states = new Map(Object.entries((defaultState !== null && defaultState !== void 0 ? defaultState : {})));
const elmsToUpdate = new Map();
const computedStates = new Map();
const appendToMap = (map, state, value) => {
const items = map.get(state);
if (!items) {
map.set(state, [value]);
}
else if (!items.includes(value)) {
items.push(value);
}
};
const get = (state) => {
const elm = getRenderingElement();
if (elm) {
appendToMap(elmsToUpdate, state, elm);
}
return states.get(state);
};
const set = (state, value) => {
if (states.get(state) !== value) {
states.set(state, value);
const elements = elmsToUpdate.get(state);
if (elements) {
elmsToUpdate.set(state, elements.filter(forceUpdate));
}
const computed = computedStates.get(state);
if (computed) {
computed.forEach(h => h());
}
}
};
const state = new Proxy(defaultState, {
get(_, propName) {
return get(propName);
},
set(_, propName, value) {
set(propName, value);
return true;
}
});
const subscribe = (gen) => {
const states = new Proxy({}, {
get(_, propName) {
appendToMap(computedStates, propName, handler);
return get(propName);
},
set(_, propName, value) {
set(propName, value);
return true;
}
});
const handler = () => {
gen(states);
};
handler();
};
return {
state,
get,
set,
subscribe
};
};
export { createStore } from './store';
export { createObservableMap } from './observable-map';
export { computedSubscription } from './subscriptions/computed';
export { stencilSubscription } from './subscriptions/stencil';
{
"name": "@stencil/store",
"version": "0.0.2",
"version": "0.1.0",
"description": "",

@@ -9,3 +9,7 @@ "module": "dist/index.js",

"build": "tsc -p .",
"lint.prettier": "node_modules/.bin/prettier --write 'src/**/*.ts'",
"release": "np",
"test": "jest",
"test.ci": "npm run test && npm run test.prettier",
"test.prettier": "node_modules/.bin/prettier --check 'src/**/*.ts'",
"version": "npm run build"

@@ -27,5 +31,11 @@ },

"devDependencies": {
"@stencil/core": "^1.8.2-1",
"np": "^5.1.3"
"@stencil/core": "1.9.0-2",
"@types/jest": "^24.0.23",
"jest": "24.8.0",
"jest-cli": "24.8.0",
"np": "^5.1.3",
"prettier": "^1.19.1",
"ts-jest": "^24.2.0",
"typescript": "^3.7.3"
}
}
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