UNPKG

better-auth

Version:

The most comprehensive authentication framework for TypeScript.

1 lines 1.49 kB
{"version":3,"file":"vue-store.mjs","names":[],"sources":["../../../src/client/vue/vue-store.ts"],"sourcesContent":["import type { Store, StoreValue } from \"nanostores\";\nimport type { DeepReadonly, ShallowRef, UnwrapNestedRefs } from \"vue\";\nimport {\n\tgetCurrentInstance,\n\tgetCurrentScope,\n\tonScopeDispose,\n\treadonly,\n\tshallowRef,\n} from \"vue\";\n\nfunction registerStore(store: Store) {\n\tlet instance = getCurrentInstance();\n\tif (instance && instance.proxy) {\n\t\tlet vm = instance.proxy as any;\n\t\tlet cache = \"_nanostores\" in vm ? vm._nanostores : (vm._nanostores = []);\n\t\tcache.push(store);\n\t}\n}\n\nexport function useStore<\n\tSomeStore extends Store,\n\tValue extends StoreValue<SomeStore>,\n>(store: SomeStore): DeepReadonly<UnwrapNestedRefs<ShallowRef<Value>>> {\n\tlet state = shallowRef();\n\n\tlet unsubscribe = store.subscribe((value) => {\n\t\tstate.value = value;\n\t});\n\n\tif (getCurrentScope()) onScopeDispose(unsubscribe);\n\n\tif (process.env.NODE_ENV !== \"production\") {\n\t\tregisterStore(store);\n\t\treturn readonly(state);\n\t}\n\treturn state;\n}\n"],"mappings":";;;AAUA,SAAS,cAAc,OAAc;CACpC,IAAI,WAAW,oBAAoB;AACnC,KAAI,YAAY,SAAS,OAAO;EAC/B,IAAI,KAAK,SAAS;AAElB,GADY,iBAAiB,KAAK,GAAG,cAAe,GAAG,cAAc,EAAE,EACjE,KAAK,MAAM;;;AAInB,SAAgB,SAGd,OAAqE;CACtE,IAAI,QAAQ,YAAY;CAExB,IAAI,cAAc,MAAM,WAAW,UAAU;AAC5C,QAAM,QAAQ;GACb;AAEF,KAAI,iBAAiB,CAAE,gBAAe,YAAY;AAElD,KAAI,QAAQ,IAAI,aAAa,cAAc;AAC1C,gBAAc,MAAM;AACpB,SAAO,SAAS,MAAM;;AAEvB,QAAO"}