edges-svelte 0.5.2 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@ export interface ContextData {
3
3
  event?: RequestEvent;
4
4
  symbol?: symbol;
5
5
  data: {
6
- providers?: Map<symbol, unknown>;
6
+ providers?: Map<string, unknown>;
7
7
  [p: string]: unknown;
8
8
  };
9
9
  }
@@ -6,7 +6,7 @@ type StoreDeps = {
6
6
  };
7
7
  interface CreateProviderOptions<T, I extends Record<string, unknown> = Record<string, unknown>> {
8
8
  inject?: I;
9
- cache?: boolean;
9
+ cacheKey?: string;
10
10
  factory: (args: StoreDeps & I) => T;
11
11
  }
12
12
  export declare const createProvider: <T, I extends Record<string, unknown> = Record<string, unknown>>(options: CreateProviderOptions<T, I>) => (() => T);
@@ -11,11 +11,9 @@ export const createProvider = (options) => {
11
11
  },
12
12
  ...(options.inject || {})
13
13
  };
14
- const cacheKey = Symbol();
15
- const cache = options.cache ?? true;
16
- console.log('cache-key', cacheKey);
14
+ const cacheKey = options.cacheKey;
17
15
  return () => {
18
- if (!cache) {
16
+ if (!cacheKey) {
19
17
  return options.factory(deps);
20
18
  }
21
19
  if (browser) {
@@ -29,7 +27,6 @@ export const createProvider = (options) => {
29
27
  if (!context.data.providers) {
30
28
  context.data.providers = new Map();
31
29
  }
32
- console.log(RequestContext.current().data.providers);
33
30
  const map = context.data.providers;
34
31
  if (!map.has(cacheKey)) {
35
32
  map.set(cacheKey, options.factory(deps));
@@ -86,15 +86,22 @@ export const createDerivedState = (stores, deriveFn) => {
86
86
  if (browser) {
87
87
  return derived(stores, deriveFn);
88
88
  }
89
- const values = stores.map((s) => {
90
- let value;
91
- s.subscribe((v) => (value = v))();
92
- return value;
93
- });
94
89
  return {
95
90
  subscribe(run) {
96
- run(deriveFn(values));
97
- return () => { };
91
+ const values = new Array(stores.length);
92
+ let initializedCount = 0;
93
+ const unsubscribers = stores.map((store, i) => store.subscribe((value) => {
94
+ values[i] = value;
95
+ if (initializedCount < stores.length) {
96
+ initializedCount++;
97
+ }
98
+ if (initializedCount >= stores.length) {
99
+ run(deriveFn(values));
100
+ }
101
+ }));
102
+ return () => {
103
+ unsubscribers.forEach((unsub) => unsub());
104
+ };
98
105
  }
99
106
  };
100
107
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "edges-svelte",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "license": "MIT",
5
5
  "author": "Pixel1917",
6
6
  "description": "A blazing-fast, extremely lightweight and SSR-friendly store for Svelte",