stunk 0.3.0 → 0.7.0

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.
package/dist/core.js DELETED
@@ -1,23 +0,0 @@
1
- export function createChunk(initialValue) {
2
- let value = initialValue;
3
- const subscribers = [];
4
- const get = () => value;
5
- const set = (newValue) => {
6
- if (newValue !== value) {
7
- value = newValue;
8
- subscribers.forEach((subscriber) => subscriber(value)); // Notify all subscribers
9
- }
10
- };
11
- const subscribe = (callback) => {
12
- subscribers.push(callback);
13
- callback(value); // Immediately notify on subscription
14
- // Return unsubscribe function
15
- return () => {
16
- const index = subscribers.indexOf(callback);
17
- if (index >= 0) {
18
- subscribers.splice(index, 1);
19
- }
20
- };
21
- };
22
- return { get, set, subscribe };
23
- }
package/src/core.ts DELETED
@@ -1,36 +0,0 @@
1
- export type Subscriber<T> = (newValue: T) => void;
2
-
3
- export interface Chunk<T> {
4
- get: () => T;
5
- set: (value: T) => void;
6
- subscribe: (callback: Subscriber<T>) => () => void;
7
- }
8
-
9
- export function createChunk<T>(initialValue: T): Chunk<T> {
10
- let value = initialValue;
11
- const subscribers: Subscriber<T>[] = [];
12
-
13
- const get = () => value;
14
-
15
- const set = (newValue: T) => {
16
- if (newValue !== value) {
17
- value = newValue;
18
- subscribers.forEach((subscriber) => subscriber(value)); // Notify all subscribers
19
- }
20
- };
21
-
22
- const subscribe = (callback: Subscriber<T>) => {
23
- subscribers.push(callback);
24
- callback(value); // Immediately notify on subscription
25
-
26
- // Return unsubscribe function
27
- return () => {
28
- const index = subscribers.indexOf(callback);
29
- if (index >= 0) {
30
- subscribers.splice(index, 1);
31
- }
32
- };
33
- };
34
-
35
- return { get, set, subscribe };
36
- }