better-auth
Version:
The most comprehensive authentication framework for TypeScript.
1 lines • 1.36 kB
Source Map (JSON)
{"version":3,"file":"solid-store.mjs","names":[],"sources":["../../../src/client/solid/solid-store.ts"],"sourcesContent":["import type { Store, StoreValue } from \"nanostores\";\nimport type { Accessor } from \"solid-js\";\nimport { onCleanup } from \"solid-js\";\nimport { createStore, reconcile } from \"solid-js/store\";\n\n/**\n * Subscribes to store changes and gets store’s value.\n *\n * @param store Store instance.\n * @returns Store value.\n */\nexport function useStore<\n\tSomeStore extends Store,\n\tValue extends StoreValue<SomeStore>,\n>(store: SomeStore): Accessor<Value> {\n\t// Activate the store explicitly:\n\t// https://github.com/nanostores/solid/issues/19\n\tconst unbindActivation = store.listen(() => {});\n\n\tconst [state, setState] = createStore({\n\t\tvalue: store.get(),\n\t});\n\n\tconst unsubscribe = store.subscribe((newValue) => {\n\t\tsetState(\"value\", reconcile(newValue));\n\t});\n\n\tonCleanup(() => unsubscribe());\n\n\t// Remove temporary listener now that there is already a proper subscriber.\n\tunbindActivation();\n\n\treturn () => state.value;\n}\n"],"mappings":";;;;;;;;;;AAWA,SAAgB,SAGd,OAAmC;CAGpC,MAAM,mBAAmB,MAAM,aAAa,GAAG;CAE/C,MAAM,CAAC,OAAO,YAAY,YAAY,EACrC,OAAO,MAAM,KAAK,EAClB,CAAC;CAEF,MAAM,cAAc,MAAM,WAAW,aAAa;AACjD,WAAS,SAAS,UAAU,SAAS,CAAC;GACrC;AAEF,iBAAgB,aAAa,CAAC;AAG9B,mBAAkB;AAElB,cAAa,MAAM"}