Skip to content

Commit 888a56b

Browse files
committed
v1.0.0
* feat next version (v1.0.0) * refine types & code * test coverage: set, reset, subscribe * test coverage: action * test: coverage: computed values * test coverage: core * test coverage: fp utility functions * test coverage: proxy * test coverage: subscription * chore: update readme
1 parent 1f7fca8 commit 888a56b

40 files changed

+8115
-17387
lines changed

README.md

Lines changed: 292 additions & 264 deletions
Large diffs are not rendered by default.

package-lock.json

Lines changed: 6671 additions & 16872 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "holycow",
3-
"version": "0.1.1",
3+
"version": "1.0.0",
44
"private": true,
55
"keywords": [
66
"state management",
@@ -9,22 +9,33 @@
99
"license": "MIT",
1010
"author": "sultan99",
1111
"main": "index.js",
12+
"repository": {
13+
"type": "git",
14+
"url": "https://github.com/sultan99/holycow"
15+
},
16+
"scripts": {
17+
"test": "jest --coverage --config=packages/state/jest.config.js",
18+
"test:watch": "jest --watch --config=packages/state/jest.config.js",
19+
"tsc": "tsc -w"
20+
},
1221
"devDependencies": {
13-
"@babel/core": "^7.19.3",
14-
"@babel/preset-env": "^7.19.3",
22+
"@babel/core": "^7.19.6",
23+
"@babel/preset-env": "^7.19.4",
1524
"@babel/preset-typescript": "^7.18.6",
16-
"@types/jest": "^29.1.1",
17-
"@types/node": "^18.8.0",
18-
"@types/ramda": "^0.28.15",
19-
"@types/react": "^18.0.21",
20-
"@typescript-eslint/eslint-plugin": "^5.38.1",
21-
"@typescript-eslint/parser": "^5.38.1",
22-
"babel-jest": "^29.1.2",
23-
"eslint": "^8.24.0",
24-
"eslint-plugin-jest": "^27.0.4",
25-
"eslint-plugin-react": "^7.31.8",
26-
"jest": "^29.1.2",
25+
"@types/jest": "^29.2.0",
26+
"@types/node": "^18.11.7",
27+
"@types/react": "^18.0.24",
28+
"@types/react-dom": "^18.0.8",
29+
"@typescript-eslint/eslint-plugin": "^5.41.0",
30+
"@typescript-eslint/parser": "^5.41.0",
31+
"babel-jest": "^29.2.2",
32+
"eslint": "^8.26.0",
33+
"eslint-plugin-jest": "^27.1.3",
34+
"eslint-plugin-react": "^7.31.10",
35+
"jest": "^29.2.2",
36+
"jest-environment-jsdom": "^29.2.2",
2737
"react": "^18.2.0",
38+
"react-dom": "^18.2.0",
2839
"typescript": "^4.8.4"
2940
}
3041
}

packages/state/jest.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
module.exports = {
2+
testEnvironment: `jsdom`,
3+
testMatch: [`**/specs.ts`],
24
testPathIgnorePatterns: [
5+
`<rootDir>/dist/`,
36
`<rootDir>/node_modules/`,
47
],
58
}

packages/state/package-lock.json

Lines changed: 0 additions & 85 deletions
This file was deleted.

packages/state/package.json

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "@holycow/state",
3-
"version": "0.1.1",
3+
"version": "1.0.0",
44
"license": "MIT",
55
"repository": {
66
"type": "git",
7-
"url": "https://github.com/sultan99/restate",
8-
"directory": "packages/store"
7+
"url": "https://github.com/sultan99/holycow",
8+
"directory": "packages/state"
99
},
1010
"author": "sultan99",
1111
"main": "dist/index",
@@ -25,10 +25,6 @@
2525
"tsc": "tsc -w"
2626
},
2727
"peerDependencies": {
28-
"ramda": "^0.27.1",
2928
"react": "^18.2.0"
30-
},
31-
"publishConfig": {
32-
"access": "public"
3329
}
3430
}

packages/state/src/action/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type {Action} from './types'
2+
3+
const actionFns = new WeakSet<Action<any, any>>()
4+
5+
export const isAction = <I>(fn: Action<I, any>) => actionFns.has(fn)
6+
7+
export const action = <I, R>(fn: Action<I, R>) => {
8+
actionFns.add(fn)
9+
return fn
10+
}

packages/state/src/action/readme.md

Whitespace-only changes.

packages/state/src/action/specs.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {act} from 'react-dom/test-utils'
2+
import {renderHook} from '../test-utils'
3+
import {usePosts} from '../test-utils/posts'
4+
5+
afterEach(() => {
6+
usePosts.reset()
7+
})
8+
9+
describe(`🎬 Action`, () => {
10+
const newPost = {id: 5, title: `Hello World`}
11+
12+
it(`should set a value via action`, () => {
13+
act(() => usePosts.addPost(newPost))
14+
expect(usePosts.posts[4]).toEqual(newPost)
15+
expect(usePosts.posts.length).toBe(5)
16+
})
17+
18+
it(`should set a value via action using hook`, () => {
19+
const {result} = renderHook(usePosts)
20+
act(() => result.addPost(newPost))
21+
expect(result.posts[4]).toEqual(newPost)
22+
expect(result.posts.length).toBe(5)
23+
})
24+
})

packages/state/src/action/types.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type {ProxyState} from '../proxy/types'
2+
import type {State} from '../core/types'
3+
import type {ValOrFunc} from '../fp/types'
4+
5+
export type SetPayload<P> = P extends string ? P : never
6+
7+
export type Action<I, A = undefined> = (state: ProxyState<State<I>>) =>
8+
A extends any[]
9+
? (...args: A) => void
10+
: A extends SetPayload<A>
11+
? (payload: ValOrFunc<I, A>) => void
12+
: A extends undefined
13+
? () => void
14+
: A

0 commit comments

Comments
 (0)