Skip to content

Commit

Permalink
Added lit-signal-watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
guillemcordoba committed Apr 25, 2024
1 parent bdbeef1 commit 7b38c40
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 23 deletions.
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions packages/signals/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@holochain-open-dev/signals",
"version": "0.300.0-dev.0",
"version": "0.300.0-dev.1",
"description": "Holochain async-signals to build reusable holochain-open-dev modules",
"author": "[email protected]",
"main": "dist/index.js",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"files": ["dist"],
"files": ["dist", "src"],
"exports": {
".": "./dist/index.js",
"./dist/*": "./dist/*"
Expand All @@ -23,6 +23,7 @@
"@holochain/client": "^0.17.0-dev.9",
"@shoelace-style/shoelace": "^2.11.2",
"async-signals": "^0.1.1",
"lit-signal-watcher": "^0.1.0",
"signal-polyfill": "^0.1.0"
},
"devDependencies": {
Expand Down
27 changes: 6 additions & 21 deletions packages/signals/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import { Signal } from "signal-polyfill";

export * from "./join-map.js";
export * from "./utils.js";
export * from "./holochain.js";

export * from "signal-polyfill";
// Omit joinAsyncMap because we provide the holohash implementation version in join-map.ts
export {
AsyncComputed,
Expand All @@ -15,19 +10,9 @@ export {
JoinAsyncOptions,
toPromise,
} from "async-signals";
export * from "lit-signal-watcher";

export function watch<T>(
signal: Signal.State<T> | Signal.Computed<T>,
callback: (value: T) => void
): () => void {
const w = new Signal.subtle.Watcher(() => {
setTimeout(() => {
callback(signal.get());
});
});
w.watch(signal);

return () => {
w.unwatch(signal);
};
}
export * from "./join-map.js";
export * from "./utils.js";
export * from "./holochain.js";
export * from "./watch.js";
17 changes: 17 additions & 0 deletions packages/signals/src/watch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Signal } from "signal-polyfill";

export function watch<T>(
signal: Signal.State<T> | Signal.Computed<T>,
callback: (value: T) => void
): () => void {
const w = new Signal.subtle.Watcher(() => {
setTimeout(() => {
callback(signal.get());
});
});
w.watch(signal);

return () => {
w.unwatch(signal);
};
}

0 comments on commit 7b38c40

Please sign in to comment.