@stencil/store
Advanced tools
Comparing version 0.0.2 to 0.1.0
@@ -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" | ||
} | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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 README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
10153
16
216
0
66
8
1