diff --git a/package-lock.json b/package-lock.json index 1bb4822d5..045e8e3da 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "solid-js", - "version": "0.5.1-beta.3", + "version": "0.5.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -14,18 +14,18 @@ } }, "@babel/core": { - "version": "7.4.3", - "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.4.3.tgz", - "integrity": "sha512-oDpASqKFlbspQfzAE7yaeTmdljSH2ADIvBlb0RwbStltTuWa0+7CCI1fYVINNv9saHPa1W7oaKeuNuKj+RQCvA==", + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.4.4.tgz", + "integrity": "sha512-lQgGX3FPRgbz2SKmhMtYgJvVzGZrmjaF4apZ2bLwofAKiSjxU0drPh4S/VasyYXwaTs+A1gvQ45BN8SQJzHsQQ==", "dev": true, "requires": { "@babel/code-frame": "^7.0.0", - "@babel/generator": "^7.4.0", - "@babel/helpers": "^7.4.3", - "@babel/parser": "^7.4.3", - "@babel/template": "^7.4.0", - "@babel/traverse": "^7.4.3", - "@babel/types": "^7.4.0", + "@babel/generator": "^7.4.4", + "@babel/helpers": "^7.4.4", + "@babel/parser": "^7.4.4", + "@babel/template": "^7.4.4", + "@babel/traverse": "^7.4.4", + "@babel/types": "^7.4.4", "convert-source-map": "^1.1.0", "debug": "^4.1.0", "json5": "^2.1.0", @@ -35,6 +35,73 @@ "source-map": "^0.5.0" }, "dependencies": { + "@babel/generator": { + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.4.4.tgz", + "integrity": "sha512-53UOLK6TVNqKxf7RUh8NE851EHRxOOeVXKbK2bivdb+iziMyk03Sr4eaE9OELCbyZAAafAKPDwF2TPUES5QbxQ==", + "dev": true, + "requires": { + "@babel/types": "^7.4.4", + "jsesc": "^2.5.1", + "lodash": "^4.17.11", + "source-map": "^0.5.0", + "trim-right": "^1.0.1" + } + }, + "@babel/helper-split-export-declaration": { + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.4.4.tgz", + "integrity": "sha512-Ro/XkzLf3JFITkW6b+hNxzZ1n5OQ80NvIUdmHspih1XAhtN3vPTuUFT4eQnela+2MaZ5ulH+iyP513KJrxbN7Q==", + "dev": true, + "requires": { + "@babel/types": "^7.4.4" + } + }, + "@babel/parser": { + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.4.4.tgz", + "integrity": "sha512-5pCS4mOsL+ANsFZGdvNLybx4wtqAZJ0MJjMHxvzI3bvIsz6sQvzW8XX92EYIkiPtIvcfG3Aj+Ir5VNyjnZhP7w==", + "dev": true + }, + "@babel/template": { + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.4.4.tgz", + "integrity": "sha512-CiGzLN9KgAvgZsnivND7rkA+AeJ9JB0ciPOD4U59GKbQP2iQl+olF1l76kJOupqidozfZ32ghwBEJDhnk9MEcw==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.0.0", + "@babel/parser": "^7.4.4", + "@babel/types": "^7.4.4" + } + }, + "@babel/traverse": { + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.4.4.tgz", + "integrity": "sha512-Gw6qqkw/e6AGzlyj9KnkabJX7VcubqPtkUQVAwkc0wUMldr3A/hezNB3Rc5eIvId95iSGkGIOe5hh1kMKf951A==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.0.0", + "@babel/generator": "^7.4.4", + "@babel/helper-function-name": "^7.1.0", + "@babel/helper-split-export-declaration": "^7.4.4", + "@babel/parser": "^7.4.4", + "@babel/types": "^7.4.4", + "debug": "^4.1.0", + "globals": "^11.1.0", + "lodash": "^4.17.11" + } + }, + "@babel/types": { + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.4.4.tgz", + "integrity": "sha512-dOllgYdnEFOebhkKCjzSVFqw/PmmB8pH6RGOWkY4GsboQNd47b1fBThBSwlHAq9alF9vc1M3+6oqR47R50L0tQ==", + "dev": true, + "requires": { + "esutils": "^2.0.2", + "lodash": "^4.17.11", + "to-fast-properties": "^2.0.0" + } + }, "debug": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", @@ -124,14 +191,104 @@ } }, "@babel/helpers": { - "version": "7.4.3", - "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.4.3.tgz", - "integrity": "sha512-BMh7X0oZqb36CfyhvtbSmcWc3GXocfxv3yNsAEuM0l+fAqSO22rQrUpijr3oE/10jCTrB6/0b9kzmG4VetCj8Q==", + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.4.4.tgz", + "integrity": "sha512-igczbR/0SeuPR8RFfC7tGrbdTbFL3QTvH6D+Z6zNxnTe//GyqmtHmDkzrqDmyZ3eSwPqB/LhyKoU5DXsp+Vp2A==", "dev": true, "requires": { - "@babel/template": "^7.4.0", - "@babel/traverse": "^7.4.3", - "@babel/types": "^7.4.0" + "@babel/template": "^7.4.4", + "@babel/traverse": "^7.4.4", + "@babel/types": "^7.4.4" + }, + "dependencies": { + "@babel/generator": { + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.4.4.tgz", + "integrity": "sha512-53UOLK6TVNqKxf7RUh8NE851EHRxOOeVXKbK2bivdb+iziMyk03Sr4eaE9OELCbyZAAafAKPDwF2TPUES5QbxQ==", + "dev": true, + "requires": { + "@babel/types": "^7.4.4", + "jsesc": "^2.5.1", + "lodash": "^4.17.11", + "source-map": "^0.5.0", + "trim-right": "^1.0.1" + } + }, + "@babel/helper-split-export-declaration": { + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.4.4.tgz", + "integrity": "sha512-Ro/XkzLf3JFITkW6b+hNxzZ1n5OQ80NvIUdmHspih1XAhtN3vPTuUFT4eQnela+2MaZ5ulH+iyP513KJrxbN7Q==", + "dev": true, + "requires": { + "@babel/types": "^7.4.4" + } + }, + "@babel/parser": { + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.4.4.tgz", + "integrity": "sha512-5pCS4mOsL+ANsFZGdvNLybx4wtqAZJ0MJjMHxvzI3bvIsz6sQvzW8XX92EYIkiPtIvcfG3Aj+Ir5VNyjnZhP7w==", + "dev": true + }, + "@babel/template": { + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.4.4.tgz", + "integrity": "sha512-CiGzLN9KgAvgZsnivND7rkA+AeJ9JB0ciPOD4U59GKbQP2iQl+olF1l76kJOupqidozfZ32ghwBEJDhnk9MEcw==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.0.0", + "@babel/parser": "^7.4.4", + "@babel/types": "^7.4.4" + } + }, + "@babel/traverse": { + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.4.4.tgz", + "integrity": "sha512-Gw6qqkw/e6AGzlyj9KnkabJX7VcubqPtkUQVAwkc0wUMldr3A/hezNB3Rc5eIvId95iSGkGIOe5hh1kMKf951A==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.0.0", + "@babel/generator": "^7.4.4", + "@babel/helper-function-name": "^7.1.0", + "@babel/helper-split-export-declaration": "^7.4.4", + "@babel/parser": "^7.4.4", + "@babel/types": "^7.4.4", + "debug": "^4.1.0", + "globals": "^11.1.0", + "lodash": "^4.17.11" + } + }, + "@babel/types": { + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.4.4.tgz", + "integrity": "sha512-dOllgYdnEFOebhkKCjzSVFqw/PmmB8pH6RGOWkY4GsboQNd47b1fBThBSwlHAq9alF9vc1M3+6oqR47R50L0tQ==", + "dev": true, + "requires": { + "esutils": "^2.0.2", + "lodash": "^4.17.11", + "to-fast-properties": "^2.0.0" + } + }, + "debug": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + }, + "ms": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", + "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==", + "dev": true + }, + "source-map": { + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", + "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", + "dev": true + } } }, "@babel/highlight": { @@ -473,9 +630,9 @@ "dev": true }, "@types/node": { - "version": "11.13.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-11.13.0.tgz", - "integrity": "sha512-rx29MMkRdVmzunmiA4lzBYJNnXsW/PhG4kMBy2ATsYaDjGGR75dCFEVVROKpNwlVdcUX3xxlghKQOeDPBJobng==", + "version": "11.13.8", + "resolved": "https://registry.npmjs.org/@types/node/-/node-11.13.8.tgz", + "integrity": "sha512-szA3x/3miL90ZJxUCzx9haNbK5/zmPieGraZEe4WI+3srN0eGLiT22NXeMHmyhNEopn+IrxqMc7wdVwvPl8meg==", "dev": true }, "@types/resolve": { @@ -909,9 +1066,9 @@ "dev": true }, "builtin-modules": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.0.0.tgz", - "integrity": "sha512-hMIeU4K2ilbXV6Uv93ZZ0Avg/M91RaKXucQ+4me2Do1txxBDyDZWCBa5bJSLqoNTRpXTLwEzIk1KmloenDDjhg==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.1.0.tgz", + "integrity": "sha512-k0KL0aWZuBt2lrxrcASWDfwOLMnodeQjodT/1SxEQAXsHANgo6ZC/VEaSEHCXt7aSTZ4/4H5LKa+tBXmW7Vtvw==", "dev": true }, "cache-base": { @@ -1298,9 +1455,9 @@ "dev": true }, "dom-expressions": { - "version": "0.7.7", - "resolved": "https://registry.npmjs.org/dom-expressions/-/dom-expressions-0.7.7.tgz", - "integrity": "sha512-LpZfTbZ6VuOrjxqbVArmjFbG9imQqca2V4rMVgogzvsBYELRNMCu9ZX8yGbAmLFQj9wm/7svUzjwQVMKrqikRA==" + "version": "0.7.10", + "resolved": "https://registry.npmjs.org/dom-expressions/-/dom-expressions-0.7.10.tgz", + "integrity": "sha512-35tOZRvDItreJwc8ciur5MaSwCZPAeyVg7WdZqh8UqfGVFW2VmxDzznJePNb1DfO0yQgG+gG9SMEhMHrGmmxSA==" }, "domexception": { "version": "1.0.1", @@ -2407,9 +2564,9 @@ } }, "hyper-dom-expressions": { - "version": "0.7.3", - "resolved": "https://registry.npmjs.org/hyper-dom-expressions/-/hyper-dom-expressions-0.7.3.tgz", - "integrity": "sha512-zYDm+oGd6eBOauOIIz3YeDTSQwKiUyhhrbl9TO8bZcwegUkAJcA/YkjkLcEzTE78R2X75rybrX2b+UxXHCmy/w==", + "version": "0.7.4", + "resolved": "https://registry.npmjs.org/hyper-dom-expressions/-/hyper-dom-expressions-0.7.4.tgz", + "integrity": "sha512-UDcfq/bs9GA9tDFxt60JW6shBEGIx0ng/CagmEBAq0G/tfNHdP8QzqCgh/tShS26QGHp1ooq7Gxcs5ccEmF6hg==", "dev": true }, "iconv-lite": { @@ -3370,9 +3527,9 @@ } }, "lit-dom-expressions": { - "version": "0.7.3", - "resolved": "https://registry.npmjs.org/lit-dom-expressions/-/lit-dom-expressions-0.7.3.tgz", - "integrity": "sha512-T5KeUVwtlI7fBrlU4Bcp5i5HbHrakHojSMGhLfDbi8wmecIKJx8pJT9Gsdu1SjSC8sbwJ7CoKS2yyy69RipV0Q==", + "version": "0.7.4", + "resolved": "https://registry.npmjs.org/lit-dom-expressions/-/lit-dom-expressions-0.7.4.tgz", + "integrity": "sha512-6+MQ1EWBW4Iv9V6ENMZxMWk5YwBPXxwdmAc0LDeGEAaBuZaNIABFqq3NpfyjVZmsJvSH2YCj+oHE6hQcUN+iSg==", "dev": true }, "load-json-file": { @@ -4259,22 +4416,16 @@ } }, "rollup": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-1.10.0.tgz", - "integrity": "sha512-U9t/JaKtO0+X0pSmLVKMrAZEixrbVzITf193TiEhfoVKCnd7pDimIFo94IxUCgbn6+v5VmduHkubx2VV1s0Ftw==", + "version": "1.10.1", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-1.10.1.tgz", + "integrity": "sha512-pW353tmBE7QP622ITkGxtqF0d5gSRCVPD9xqM+fcPjudeZfoXMFW2sCzsTe2TU/zU1xamIjiS9xuFCPVT9fESw==", "dev": true, "requires": { "@types/estree": "0.0.39", - "@types/node": "^11.13.4", + "@types/node": "^11.13.5", "acorn": "^6.1.1" }, "dependencies": { - "@types/node": { - "version": "11.13.4", - "resolved": "https://registry.npmjs.org/@types/node/-/node-11.13.4.tgz", - "integrity": "sha512-+rabAZZ3Yn7tF/XPGHupKIL5EcAbrLxnTr/hgQICxbeuAfWtT0UZSfULE+ndusckBItcv4o6ZeOJplQikVcLvQ==", - "dev": true - }, "acorn": { "version": "6.1.1", "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.1.1.tgz", @@ -4294,13 +4445,13 @@ } }, "rollup-plugin-node-resolve": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/rollup-plugin-node-resolve/-/rollup-plugin-node-resolve-4.2.1.tgz", - "integrity": "sha512-zf2dcKBSv9KSnNbAPDYzwLpeI4Lc4bOsNlaRsq3ud80zquxWdu9iYA0ZgmHxFjBkbt8uHzXCGC4FkkejtngKng==", + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/rollup-plugin-node-resolve/-/rollup-plugin-node-resolve-4.2.3.tgz", + "integrity": "sha512-r+WaesPzdGEynpLZLALFEDugA4ACa5zn7bc/+LVX4vAXQQ8IgDHv0xfsSvJ8tDXUtprfBtrDtRFg27ifKjcJTg==", "dev": true, "requires": { "@types/resolve": "0.0.8", - "builtin-modules": "^3.0.0", + "builtin-modules": "^3.1.0", "is-module": "^1.0.0", "resolve": "^1.10.0" } @@ -4941,9 +5092,9 @@ } }, "typescript": { - "version": "3.4.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.4.4.tgz", - "integrity": "sha512-xt5RsIRCEaf6+j9AyOBgvVuAec0i92rgCaS3S+UVf5Z/vF2Hvtsw08wtUTJqp4djwznoAgjSxeCcU4r+CcDBJA==", + "version": "3.4.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.4.5.tgz", + "integrity": "sha512-YycBxUb49UUhdNMU5aJ7z5Ej2XGmaIBL0x34vZ82fn3hGvD+bgrMrVDpatgz2f7YxUMJxMkbWxJZeAvDxVe7Vw==", "dev": true }, "uglify-js": { diff --git a/package.json b/package.json index cae49a6b6..57c13a63e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "solid-js", "description": "A declarative JavaScript library for building user interfaces.", - "version": "0.5.1-beta.3", + "version": "0.5.1", "author": "Ryan Carniato", "license": "MIT", "repository": { @@ -21,21 +21,21 @@ "test": "npm run build && jest --coverage" }, "dependencies": { - "dom-expressions": "~0.7.7", + "dom-expressions": "~0.7.10", "s-js": "~0.4.9" }, "devDependencies": { - "@babel/core": "^7.4.3", + "@babel/core": "^7.4.4", "@babel/preset-typescript": "^7.3.3", "coveralls": "^3.0.3", "jest": "~24.7.1", "npm-run-all": "^4.1.5", - "hyper-dom-expressions": "0.7.3", - "lit-dom-expressions": "0.7.3", + "hyper-dom-expressions": "~0.7.4", + "lit-dom-expressions": "~0.7.4", "rimraf": "^2.6.3", - "rollup": "^1.10.0", + "rollup": "^1.10.1", "rollup-plugin-babel": "^4.3.2", - "rollup-plugin-node-resolve": "^4.1.0", - "typescript": "^3.4.4" + "rollup-plugin-node-resolve": "^4.2.3", + "typescript": "^3.4.5" } } diff --git a/src/state.ts b/src/state.ts index eb7052ba4..37c315631 100644 --- a/src/state.ts +++ b/src/state.ts @@ -12,10 +12,28 @@ type Proxy = { get(): any, set(): boolean } +type Partial = { [P in keyof T]?: Partial } type Wrapped = { [P in keyof T]: Proxy; } & { _state: T } - +type StateAtom = string | number | boolean | symbol | null | undefined | any[] +type StateSetter = ( + Partial + | ((prevState: Wrapped, traversed?: (string | number)[]) => Partial) +) +type NestedStateSetter = StateSetter | StateAtom | ((prevState: StateAtom, traversed?: (string | number)[]) => StateAtom) +type StatePathRange = { from?: number, to?: number, by?: number } +type StatePathPart = string | (string | number)[] | StatePathRange | ((item: any, index: number) => boolean) + +// do up to depth of 8 +type StatePath = ([string, NestedStateSetter] + | [string, StatePathPart, NestedStateSetter] + | [string, StatePathPart, StatePathPart, NestedStateSetter] + | [string, StatePathPart, StatePathPart, StatePathPart, NestedStateSetter] + | [string, StatePathPart, StatePathPart, StatePathPart, StatePathPart, NestedStateSetter] + | [string, StatePathPart, StatePathPart, StatePathPart, StatePathPart, StatePathPart, NestedStateSetter] + | [string, StatePathPart, StatePathPart, StatePathPart, StatePathPart, StatePathPart, StatePathPart, NestedStateSetter] +) function wrap(value: T): Wrapped { return value[SPROXY] || (value[SPROXY] = new Proxy(value, proxyTraps)); } export function isWrappable(obj: any) { return obj !== null && typeof obj === 'object' && (obj.__proto__ === Object.prototype || Array.isArray(obj)); } @@ -145,9 +163,10 @@ export function createState(state?: T | Wrapped) { state = unwrap(state || {}) as T; const wrappedState = wrap(state) as Wrapped; - function setState(update: object): void - function setState(...path: any[]): void - function setState(paths: any[][]): void + function setState(update: StateSetter): void + function setState(...path: StatePath): void + function setState(paths: StatePath[]): void + function setState(reconcile: (s: Wrapped) => void) : void function setState(): void { const args = arguments; S.freeze(() => {