@justscale/observable
Advanced tools
+13
-11
| { | ||
| "name": "@justscale/observable", | ||
| "version": "0.1.0", | ||
| "version": "0.1.3", | ||
| "description": "Proxy-based observable system with dirty tracking for TypeScript", | ||
@@ -44,2 +44,12 @@ "keywords": [ | ||
| ], | ||
| "scripts": { | ||
| "build": "tsc -p tsconfig.build.json", | ||
| "test": "tsx --test test/**/*.test.ts", | ||
| "test:coverage": "tsx --test --experimental-test-coverage test/**/*.test.ts", | ||
| "lint": "biome check .", | ||
| "lint:fix": "biome check --write .", | ||
| "format": "biome format --write .", | ||
| "pack:check": "pnpm pack && rm -f justscale-observable-*.tgz && test -f dist/index.js && test -f dist/index.d.ts && echo 'Package contents verified'", | ||
| "prepublishOnly": "pnpm build" | ||
| }, | ||
| "dependencies": { | ||
@@ -64,11 +74,3 @@ "zod": "^4.1.13" | ||
| "private": false, | ||
| "scripts": { | ||
| "build": "tsc -p tsconfig.build.json", | ||
| "test": "tsx --test test/**/*.test.ts", | ||
| "test:coverage": "tsx --test --experimental-test-coverage test/**/*.test.ts", | ||
| "lint": "biome check .", | ||
| "lint:fix": "biome check --write .", | ||
| "format": "biome format --write .", | ||
| "pack:check": "pnpm pack && rm -f justscale-observable-*.tgz && test -f dist/index.js && test -f dist/index.d.ts && echo 'Package contents verified'" | ||
| } | ||
| } | ||
| "packageManager": "pnpm@10.24.0" | ||
| } |
+27
-8
@@ -131,14 +131,33 @@ # @justscale/observable | ||
| Two models can share the same data. Changes through either model mark both as dirty with their respective paths: | ||
| ```typescript | ||
| const shared = createObservable({ value: 1 }); | ||
| import { z } from "zod"; | ||
| import { createModel, getModelInternals, createObservable } from "@justscale/observable"; | ||
| const model1 = createModel(schema1, { foo: shared }); | ||
| const model2 = createModel(schema2, { bar: shared }); | ||
| // Shared data | ||
| const sharedProfile = createObservable({ name: "Alice", score: 100 }); | ||
| // Modify through either path | ||
| model1.foo.value = 99; | ||
| // Two different models, different schemas, same shared data | ||
| const schema1 = z.object({ user: z.any() }); | ||
| const schema2 = z.object({ player: z.any() }); | ||
| // Both track dirty with their respective paths | ||
| getModelInternals(model1).getDirtyPaths(); // ["foo.value", "foo"] | ||
| getModelInternals(model2).getDirtyPaths(); // ["bar.value", "bar"] | ||
| const model1 = createModel(schema1, { user: sharedProfile }); | ||
| const model2 = createModel(schema2, { player: sharedProfile }); | ||
| // Modify through model1 | ||
| model1.user.score = 200; | ||
| // Both models are dirty with their own paths | ||
| getModelInternals(model1).getDirtyPaths(); // ["user.score", "user"] | ||
| getModelInternals(model2).getDirtyPaths(); // ["player.score", "player"] | ||
| // Both see the same value | ||
| model1.user.score; // 200 | ||
| model2.player.score; // 200 | ||
| // Clean model1, model2 stays dirty | ||
| getModelInternals(model1).markClean(); | ||
| getModelInternals(model1).isDirty(); // false | ||
| getModelInternals(model2).isDirty(); // true - independent dirty tracking | ||
| ``` | ||
@@ -145,0 +164,0 @@ |
59837
1.35%208
10.05%