@solid-primitives/deep 0.0.100
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +57 -0
- package/dist/index.cjs +28 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +26 -0
- package/package.json +57 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Solid Primitives Working Group
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
<p>
|
|
2
|
+
<img width="100%" src="https://assets.solidjs.com/banner?type=Primitives&background=tiles&project=deep" alt="Solid Primitives deep">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
# @solid-primitives/deep
|
|
6
|
+
|
|
7
|
+
[](https://turborepo.org/)
|
|
8
|
+
[](https://bundlephobia.com/package/@solid-primitives/deep)
|
|
9
|
+
[](https://www.npmjs.com/package/@solid-primitives/deep)
|
|
10
|
+
[](https://github.com/solidjs-community/solid-primitives#contribution-process)
|
|
11
|
+
|
|
12
|
+
A function that allows to trigger effects when deep properties for a store change:
|
|
13
|
+
|
|
14
|
+
`deepTrack` - Provides a traversed store object.
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @solid-primitives/deep
|
|
20
|
+
# or
|
|
21
|
+
yarn add @solid-primitives/deep
|
|
22
|
+
# or
|
|
23
|
+
pnpm add @solid-primitives/deep
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## How to use it
|
|
27
|
+
|
|
28
|
+
You can explicitly pass dependencies to effect functions like `on` and `defer` to deeply track its dependencies.
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
createEffect(
|
|
32
|
+
on(
|
|
33
|
+
() => deepTrack(sign),
|
|
34
|
+
() => {
|
|
35
|
+
/* function to execute */
|
|
36
|
+
},
|
|
37
|
+
),
|
|
38
|
+
);
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Or since this has a composable design, you can create _derivative_ functions and use them similar to derivative signals.
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
const deeplyTrackedStore = () => deepTrack(sign);
|
|
45
|
+
createEffect(() => {
|
|
46
|
+
console.log("Store is: ", deeplyTrackedStore());
|
|
47
|
+
// ^ this causes a re-execution of the effect on deep changes of properties
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Demo
|
|
52
|
+
|
|
53
|
+
You can use this template for publishing your demo on CodeSandbox: https://codesandbox.io/s/solid-primitives-demo-template-sz95h
|
|
54
|
+
|
|
55
|
+
## Changelog
|
|
56
|
+
|
|
57
|
+
See [CHANGELOG.md](./CHANGELOG.md)
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var solidJs = require('solid-js');
|
|
4
|
+
|
|
5
|
+
// src/index.ts
|
|
6
|
+
function deepTrack(store) {
|
|
7
|
+
return deepTraverse(store);
|
|
8
|
+
}
|
|
9
|
+
function deepTraverse(value, seen) {
|
|
10
|
+
if (!isWrappable(value)) {
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
seen = seen || /* @__PURE__ */ new Set();
|
|
14
|
+
if (seen.has(value)) {
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
seen.add(value);
|
|
18
|
+
for (const key in value) {
|
|
19
|
+
deepTraverse(value[key], seen);
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
function isWrappable(obj) {
|
|
24
|
+
let proto;
|
|
25
|
+
return obj != null && typeof obj === "object" && (obj[solidJs.$PROXY] || !(proto = Object.getPrototypeOf(obj)) || proto === Object.prototype || Array.isArray(obj));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
exports.deepTrack = deepTrack;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Store } from 'solid-js/store';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* deepTrack - create a deep getter on the given object
|
|
5
|
+
* ```typescript
|
|
6
|
+
* export function deepTrack<T>(
|
|
7
|
+
* store: Store<T>
|
|
8
|
+
* ): T;
|
|
9
|
+
* ```
|
|
10
|
+
* @param store reactive store dependency
|
|
11
|
+
* @returns same dependency, just traversed deeply to trigger effects on deeply nested properties. For example:
|
|
12
|
+
*
|
|
13
|
+
* ```typescript
|
|
14
|
+
* createEffect(
|
|
15
|
+
* on(
|
|
16
|
+
* deepTrack(store),
|
|
17
|
+
* () => {
|
|
18
|
+
* // this effect will run when any property of store changes
|
|
19
|
+
* }
|
|
20
|
+
* )
|
|
21
|
+
*
|
|
22
|
+
* );
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
declare function deepTrack<T>(store: Store<T>): T;
|
|
26
|
+
|
|
27
|
+
export { deepTrack };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { $PROXY } from 'solid-js';
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
function deepTrack(store) {
|
|
5
|
+
return deepTraverse(store);
|
|
6
|
+
}
|
|
7
|
+
function deepTraverse(value, seen) {
|
|
8
|
+
if (!isWrappable(value)) {
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
seen = seen || /* @__PURE__ */ new Set();
|
|
12
|
+
if (seen.has(value)) {
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
seen.add(value);
|
|
16
|
+
for (const key in value) {
|
|
17
|
+
deepTraverse(value[key], seen);
|
|
18
|
+
}
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
function isWrappable(obj) {
|
|
22
|
+
let proto;
|
|
23
|
+
return obj != null && typeof obj === "object" && (obj[$PROXY] || !(proto = Object.getPrototypeOf(obj)) || proto === Object.prototype || Array.isArray(obj));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { deepTrack };
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@solid-primitives/deep",
|
|
3
|
+
"version": "0.0.100",
|
|
4
|
+
"description": "Deep trigger effects for Stores.",
|
|
5
|
+
"author": "Samuel Burbano <me@iosamuel.dev>",
|
|
6
|
+
"contributors": [],
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"homepage": "https://github.com/solidjs-community/solid-primitives/tree/main/packages/deep#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/solidjs-community/solid-primitives.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/solidjs-community/solid-primitives/issues"
|
|
15
|
+
},
|
|
16
|
+
"primitive": {
|
|
17
|
+
"name": "deep",
|
|
18
|
+
"stage": 0,
|
|
19
|
+
"list": [
|
|
20
|
+
"deepTrack"
|
|
21
|
+
],
|
|
22
|
+
"category": "Reactivity"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"solid",
|
|
26
|
+
"primitives",
|
|
27
|
+
"deep"
|
|
28
|
+
],
|
|
29
|
+
"private": false,
|
|
30
|
+
"sideEffects": false,
|
|
31
|
+
"files": [
|
|
32
|
+
"dist"
|
|
33
|
+
],
|
|
34
|
+
"type": "module",
|
|
35
|
+
"main": "./dist/index.cjs",
|
|
36
|
+
"module": "./dist/index.js",
|
|
37
|
+
"browser": {},
|
|
38
|
+
"types": "./dist/index.d.ts",
|
|
39
|
+
"exports": {
|
|
40
|
+
"import": {
|
|
41
|
+
"types": "./dist/index.d.ts",
|
|
42
|
+
"default": "./dist/index.js"
|
|
43
|
+
},
|
|
44
|
+
"require": "./dist/index.cjs"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"solid-js": "^1.6.0"
|
|
48
|
+
},
|
|
49
|
+
"typesVersions": {},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"dev": "vite serve dev",
|
|
52
|
+
"page": "vite build dev",
|
|
53
|
+
"build": "jiti ../../scripts/build.ts",
|
|
54
|
+
"test": "vitest -c ../../configs/vitest.config.ts",
|
|
55
|
+
"test:ssr": "pnpm run test --mode ssr"
|
|
56
|
+
}
|
|
57
|
+
}
|