stunk 0.1.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/LICENSE +27 -0
- package/README.md +23 -0
- package/dist/core.js +22 -0
- package/dist/index.js +2 -0
- package/dist/utils.js +3 -0
- package/jest.config.js +4 -0
- package/package.json +26 -0
- package/src/core.ts +30 -0
- package/src/index.ts +4 -0
- package/src/utils.ts +3 -0
- package/tests/chunk.test.ts +35 -0
- package/tsconfig.json +15 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
---
|
|
2
|
+
|
|
3
|
+
### **`LICENSE`**
|
|
4
|
+
|
|
5
|
+
```text
|
|
6
|
+
MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2025 AbdulAzeez
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
```
|
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Stunk
|
|
2
|
+
|
|
3
|
+
**Stunk** is a framework-agnostic state management library implementing the **Atomic State technique**, utilizing chunk-based units for efficient state management. Whether you're building applications in plain JavaScript/TypeScript, React, Vue, Svelte, or any other modern framework, **Stunk** can seamlessly fit into your project.
|
|
4
|
+
|
|
5
|
+
## Pronunciation and Meaning
|
|
6
|
+
|
|
7
|
+
- **Pronunciation**: _Stunk_ (A playful blend of "state" and "chunk")
|
|
8
|
+
- **Meaning**: "Stunk" represents the combination of state management with chunk-based atomic units. The term captures the essence of atomic state management while using "chunk" to refer to these discrete units of state.
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- **Framework-agnostic**: Use it in any JavaScript/TypeScript application, regardless of framework.
|
|
13
|
+
- **Atomic State technique**: Implements state management using atomic units (chunks) that are discrete and easily manageable.
|
|
14
|
+
- **TypeScript support**: Fully typed for better developer experience and type safety.
|
|
15
|
+
- **Easy to use**: Simple API for creating, getting, and updating state.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
You can install **Stunk** from NPM:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install stunk
|
|
23
|
+
```
|
package/dist/core.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Chunk creation function
|
|
2
|
+
export function createChunk(initialValue) {
|
|
3
|
+
let value = initialValue; // The current value of the chunk
|
|
4
|
+
const subscribers = new Set(); // Set of subscribers
|
|
5
|
+
return {
|
|
6
|
+
// Get the current value
|
|
7
|
+
get() {
|
|
8
|
+
return value;
|
|
9
|
+
},
|
|
10
|
+
// Set a new value and notify subscribers
|
|
11
|
+
set(newValue) {
|
|
12
|
+
value = newValue;
|
|
13
|
+
subscribers.forEach((callback) => callback(value));
|
|
14
|
+
},
|
|
15
|
+
// Subscribe to changes
|
|
16
|
+
subscribe(callback) {
|
|
17
|
+
subscribers.add(callback);
|
|
18
|
+
// Return an unsubscribe function
|
|
19
|
+
return () => subscribers.delete(callback);
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
package/dist/index.js
ADDED
package/dist/utils.js
ADDED
package/jest.config.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "stunk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Stunk - A framework-agnostic state management library implementing the Atomic State technique, utilizing chunk-based units for efficient state management.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/types/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"test": "jest",
|
|
10
|
+
"prepare": "npm run build"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"state-management",
|
|
14
|
+
"atomic-state",
|
|
15
|
+
"framework-agnostic",
|
|
16
|
+
"dàrá"
|
|
17
|
+
],
|
|
18
|
+
"author": "AbdulAzeez",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/jest": "^29.5.14",
|
|
22
|
+
"jest": "^29.7.0",
|
|
23
|
+
"ts-jest": "^29.2.5",
|
|
24
|
+
"typescript": "^5.0.0"
|
|
25
|
+
}
|
|
26
|
+
}
|
package/src/core.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Define the Chunk type
|
|
2
|
+
export type Chunk<T> = {
|
|
3
|
+
get: () => T; // Get the value of the chunk
|
|
4
|
+
set: (newValue: T) => void; // Set the value of the chunk
|
|
5
|
+
subscribe: (callback: (value: T) => void) => () => void; // Subscribe to changes
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// Chunk creation function
|
|
9
|
+
export function createChunk<T>(initialValue: T): Chunk<T> {
|
|
10
|
+
let value = initialValue; // The current value of the chunk
|
|
11
|
+
const subscribers = new Set<(value: T) => void>(); // Set of subscribers
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
// Get the current value
|
|
15
|
+
get() {
|
|
16
|
+
return value;
|
|
17
|
+
},
|
|
18
|
+
// Set a new value and notify subscribers
|
|
19
|
+
set(newValue: T) {
|
|
20
|
+
value = newValue;
|
|
21
|
+
subscribers.forEach((callback) => callback(value));
|
|
22
|
+
},
|
|
23
|
+
// Subscribe to changes
|
|
24
|
+
subscribe(callback: (value: T) => void) {
|
|
25
|
+
subscribers.add(callback);
|
|
26
|
+
// Return an unsubscribe function
|
|
27
|
+
return () => subscribers.delete(callback);
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
package/src/index.ts
ADDED
package/src/utils.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// tests/chunk.test.ts
|
|
2
|
+
|
|
3
|
+
import { createChunk } from "../src/core";
|
|
4
|
+
|
|
5
|
+
test("Chunk should get and set values correctly", () => {
|
|
6
|
+
const chunk = createChunk<number>(0);
|
|
7
|
+
expect(chunk.get()).toBe(0);
|
|
8
|
+
chunk.set(10);
|
|
9
|
+
expect(chunk.get()).toBe(10);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test("Chunk should notify subscribers on value change", () => {
|
|
13
|
+
const chunk = createChunk<number>(0);
|
|
14
|
+
const callback = jest.fn();
|
|
15
|
+
chunk.subscribe(callback);
|
|
16
|
+
|
|
17
|
+
chunk.set(5);
|
|
18
|
+
expect(callback).toHaveBeenCalledWith(5);
|
|
19
|
+
|
|
20
|
+
chunk.set(10);
|
|
21
|
+
expect(callback).toHaveBeenCalledWith(10);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("Chunk should allow unsubscribing from updates", () => {
|
|
25
|
+
const chunk = createChunk<number>(0);
|
|
26
|
+
const callback = jest.fn();
|
|
27
|
+
const unsubscribe = chunk.subscribe(callback);
|
|
28
|
+
|
|
29
|
+
chunk.set(5);
|
|
30
|
+
expect(callback).toHaveBeenCalledWith(5);
|
|
31
|
+
|
|
32
|
+
unsubscribe();
|
|
33
|
+
chunk.set(10); // No callback should be called now
|
|
34
|
+
expect(callback).toHaveBeenCalledTimes(1);
|
|
35
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "Node",
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"declarationDir": "./dist/types",
|
|
9
|
+
"strict": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"skipLibCheck": true
|
|
12
|
+
},
|
|
13
|
+
"include": ["src/**/*"],
|
|
14
|
+
"exclude": ["node_modules", "dist"]
|
|
15
|
+
}
|