Last active
November 13, 2023 08:39
-
-
Save developit/a0430c500f5559b715c2dddf9c40948d to your computer and use it in GitHub Desktop.
Revisions
-
developit revised this gist
Jul 14, 2018 . 1 changed file with 14 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1,14 @@ { "name": "valoo", "version": "2.1.0", "module": "valoo.mjs", "main": "dist/valoo.js", "types": "./valoo.d.ts", "license": "Apache-2.0", "scripts": { "prepublishOnly": "cp *valoo.md README.md;microbundle valoo.mjs" }, "devDependencies": { "microbundle": "^0.5.1" } } -
developit revised this gist
Jul 14, 2018 . 2 changed files with 14 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1 @@ {"name":"valoo","version":"2.0.0","module":"valoo.mjs","main":"dist/valoo.js","types":"./valoo.d.ts","license":"Apache-2.0","scripts":{"prepublishOnly":"cp *valoo.md README.md;microbundle valoo.mjs"},"devDependencies":{"microbundle":"^0.5.1"}} This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ declare module "valoo" { namespace valoo { type Disposer = () => void; interface Observable<T> { (): T; (value: T): void; on(fn: (value: T) => void): Disposer; } } function valoo<T = any>(value: T): valoo.Observable<T>; export = valoo; } -
developit revised this gist
Jul 7, 2018 . No changes.There are no files selected for viewing
-
developit revised this gist
Jul 6, 2018 . 1 changed file with 6 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ <h1 align=center>🐻 valoo</h1> <p align=center><em>just the bare necessities of state management.</em></p> <p align=center><img src="https://i.imgur.com/Ke0BCSf.jpg" width="572"></p> ## Usage @@ -15,10 +15,10 @@ import valoo from 'https://unpkg.com/valoo' const num = valoo(42) // subscribe to value changes: const off = num.on( v => console.log(v) ) // unsubscribe that listener: off() // set the value, invoking any listeners: num(43) @@ -27,9 +27,10 @@ num(43) num() // 43 ``` ## Other Versions - `valoo-lite.mjs`: lighter 120b version, but doesn't support unsubscribing. - `valoo-original.mjs`: v1-compatible, with subscribe handled via overloading. ## Credit -
developit revised this gist
Jul 6, 2018 . No changes.There are no files selected for viewing
-
developit revised this gist
Jul 6, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1 @@ {"name":"valoo","version":"2.0.0","module":"valoo.mjs","main":"dist/valoo.js","license":"Apache-2.0","scripts":{"prepublishOnly":"cp *valoo.md README.md;microbundle valoo.mjs"},"devDependencies":{"microbundle":"^0.5.1"}} -
developit revised this gist
Jul 6, 2018 . 2 changed files with 16 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ export default (v, cb=[]) => c => { if (c===void 0) return v if (c.call) return cb.splice.bind(cb, cb.push(c)-1, 1, 0) v = c; for (c of cb) c && c(v) } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,12 @@ export default function valoo(v) { const cb = []; function value(c) { if (arguments.length) cb.map(f => { f && f(v=c); }); return v; } value.on = c => { const i = cb.push(c)-1; return () => { cb[i] = 0; }; }; return value; } -
developit revised this gist
Jul 6, 2018 . No changes.There are no files selected for viewing
-
developit revised this gist
Jul 6, 2018 . No changes.There are no files selected for viewing
-
developit revised this gist
Jul 6, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1 @@ {"name":"valoo","version":"1.0.2","module":"valoo.mjs","main":"dist/valoo.umd.js","license":"Apache-2.0","scripts":{"prepublishOnly":"cp *valoo.md README.md;microbundle valoo.mjs"},"devDependencies":{"microbundle":"^0.5.1"}} -
developit revised this gist
Jul 6, 2018 . 2 changed files with 5 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ node_modules package-lock.json dist README.md This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1 @@ {"name":"valoo","version":"1.0.1","module":"valoo.mjs","main":"dist/valoo.umd.js","license":"Apache-2.0","scripts":{"prepublishOnly":"cp *valoo.md README.md;microbundle valoo.mjs"},"devDependencies":{"microbundle":"^0.5.1"}} -
developit revised this gist
Jul 6, 2018 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,12 +4,12 @@ ## Usage Hotlink it from `https://unpkg.com/valoo`. See [Interactive Codepen Demo](https://codepen.io/developit/pen/NzZoVp?editors=1010). ```js import valoo from 'https://unpkg.com/valoo' // create an observable value: const num = valoo(42) -
developit revised this gist
Jul 6, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1 @@ {"name":"valoo","version":"1.0.1","main":"valoo.mjs","license":"Apache-2.0","scripts":{"prepublishOnly":"cp *valoo.md README.md","postpublish": "rm README.md"}} -
developit revised this gist
Jul 6, 2018 . No changes.There are no files selected for viewing
-
developit revised this gist
Jul 6, 2018 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,6 +4,8 @@ ## Usage Hotlink it from `https://rawgit.com/developit/a0430c500f5559b715c2dddf9c40948d/raw/valoo.mjs`. See [Interactive Codepen Demo](https://codepen.io/developit/pen/NzZoVp?editors=1010). ```js -
developit revised this gist
Jul 6, 2018 . No changes.There are no files selected for viewing
-
developit revised this gist
Jul 6, 2018 . No changes.There are no files selected for viewing
-
developit revised this gist
Jul 6, 2018 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ {"name":"valoo","version":"1.0.0","main":"valoo.mjs","author":"developit","license":"Apache-2.0"} -
developit revised this gist
Jul 6, 2018 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -29,6 +29,11 @@ num() // 43 The light version is smaller but doesn't support unsubscribing. ## Credit The idea here was first implemented in [Mithril](https://mithril.js.org). I believe the subscription mechanism is new though. ## License Apache-2.0. Copyright 2018 Google LLC. -
developit revised this gist
Jul 6, 2018 . No changes.There are no files selected for viewing
-
developit created this gist
Jul 6, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ <h1 align=center>🐻 valoo</h1> <p align=center><em>just the bare necessities of state management.</em></p> <p align=center><img src="https://i.imgur.com/bRPpZrT.png" width="572"></p> ## Usage See [Interactive Codepen Demo](https://codepen.io/developit/pen/NzZoVp?editors=1010). ```js import valoo from 'valoo' // create an observable value: const num = valoo(42) // subscribe to value changes: const unsub = num( v => console.log(v) ) // unsubscribe that listener: unsub() // set the value, invoking any listeners: num(43) // get the current value: num() // 43 ``` ## valoo-lite The light version is smaller but doesn't support unsubscribing. ## License Apache-2.0. Copyright 2018 Google LLC. This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ export default (v, cb=[]) => c => c===void 0 ? v : c.call ? cb.push(c) : cb.map(f=>f(v=c)) && v This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ export default (v, cb=[]) => c => { if (c===void 0) return v if (c.call) return cb.splice.bind(cb, cb.push(c)-1, 1, 0) v = c; for (c of cb) c && c(v) }