Skip to content

Commit 3219f7f

Browse files
authored
Feat/pool: pool and remove provider (#119)
* First pool introduction, states get pooled now and only instance per key * introduce core package tests and fix tests, preparing to remove provider and manager * first ever working new rewrite of pooling without provider at all * remove effects creator from instance * update docs to remove provider * publish pre2
1 parent 0b9636a commit 3219f7f

File tree

74 files changed

+1467
-3139
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1467
-3139
lines changed

README.MD

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ The library can work with the following modes:
2222
- `Synchronous` and/or `Asynchronous`
2323
- Data fetching and/or any form of asynchrony
2424
- Inside and/or outside `React`
25-
- Inside and/or outside `React context provider`
2625
- With or without `Cache`
2726
- `Promises`, `async/await` and even `generators` or nothing at all
2827
- Allows abstractions on top of it
@@ -120,15 +119,9 @@ runc({
120119
```
121120

122121
#### <ins>Dynamic creation and sharing of states at runtime</ins>
123-
Under the `AsyncStateProvider`, you can create and share state instances
124-
and access them by their `key` via the `hoist` option.
125-
126-
You can even start listening to a state before it gets hoisted to the provider,
127-
and get notified once it gets added.
128-
129-
#### <ins>Works with or without a provider</ins>
130-
The library can work without the provider and still share state via the
131-
`source` special object.
122+
Any created state is accessible from the whole v8 scope under the key it was
123+
given to it. So it is important to think about giving unique names to any
124+
state you create.
132125

133126
#### <ins>Apply effects or runs: debounce, throttle...</ins>
134127
To avoid creating additional state pieces and third party utilities,
@@ -220,7 +213,6 @@ const {state} = useAsyncState({source: references, lane: 'roles', lazy: false});
220213
// can be simplified to this:
221214
const {state} = useSourceLane(references, 'roles');
222215

223-
// re-use a state with its producer called weather present in the provider
224216
const {state: weatherState} = useAsyncState({key: "weather", fork: true});
225217

226218
```
@@ -232,7 +224,7 @@ The library has two ways to select data from states:
232224
current state and the whole cache (you can decide to just work with cache, if you want to!)
233225
- via `useSelector`: This hook allows you to select data from one or multiple
234226
pieces of states, it even allows combining `keys` and `source` object to select from them.
235-
It also can dynamically select states from the provider as they get hoisted.
227+
It also can dynamically select states as they get created.
236228

237229
#### <ins>And many more</ins>
238230

packages/core/jest.config.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} */
2+
module.exports = {
3+
preset: 'ts-jest',
4+
testEnvironment: 'jsdom',
5+
moduleDirectories: ['node_modules', 'src', '<rootDir>/..'],
6+
transform: {
7+
'^.+\\.ts$': ['ts-jest', {tsConfig: '<rootDir>/tsconfig.test.json'}],
8+
'^.+\\.js$': 'babel-jest',
9+
'^.+\\.mjs$': 'babel-jest',
10+
},
11+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
12+
coveragePathIgnorePatterns: [
13+
"__tests__",
14+
"index-prod.js",
15+
"configuration-warn",
16+
"type*.ts"
17+
],
18+
testMatch: [
19+
"**/*.test.js",
20+
"**/*.test.ts",
21+
"**/*.test.tsx"
22+
],
23+
};

packages/core/package.json

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,19 @@
44
"author": "incepter",
55
"sideEffects": false,
66
"name": "async-states",
7-
"version": "1.0.0-pre-1",
7+
"version": "1.0.0-pre-2",
88
"main": "dist/umd/index",
9-
"types": "dist/es/index",
10-
"module": "dist/es/index",
9+
"types": "dist/es/src/index",
10+
"module": "dist/es/src/index",
1111
"description": "Core of async-states",
1212
"devDependencies": {
13-
"@types/node": "^18.11.9"
14-
},
15-
"scripts": {
16-
"clean:dist": "rimraf dist",
17-
"start": "pnpm dev",
18-
"prebuild": "pnpm test && rimraf dist",
19-
"build": "pnpm clean:dist && rollup -c rollup/rollup.config.js",
20-
"dev": "pnpm clean:dist && rollup -c rollup/rollup.config.dev.js -w"
21-
},
22-
"dependencies": {
2313
"@babel/plugin-proposal-class-properties": "^7.18.6",
2414
"@babel/preset-env": "^7.20.2",
2515
"@babel/preset-typescript": "^7.18.6",
2616
"@jest/globals": "^29.3.1",
2717
"@rollup/plugin-babel": "^6.0.2",
2818
"@rollup/plugin-commonjs": "^23.0.2",
29-
"@rollup/plugin-json": "^5.0.1",
19+
"@rollup/plugin-json": "^5.0.2",
3020
"@rollup/plugin-node-resolve": "^15.0.1",
3121
"@rollup/plugin-replace": "^5.0.1",
3222
"@rollup/plugin-terser": "^0.1.0",
@@ -52,6 +42,15 @@
5242
"tslib": "^2.4.1",
5343
"ttypescript": "^1.5.15"
5444
},
45+
"scripts": {
46+
"test": "cross-env CI=1 jest test",
47+
"test:cov": "cross-env CI=1 jest test --coverage",
48+
"clean:dist": "rimraf dist",
49+
"start": "pnpm dev",
50+
"prebuild": "pnpm test && rimraf dist",
51+
"build": "pnpm clean:dist && rollup -c rollup/rollup.config.js",
52+
"dev": "pnpm clean:dist && rollup -c rollup/rollup.config.dev.js -w"
53+
},
5554
"engines": {
5655
"npm": ">=5",
5756
"node": ">=8"

packages/core/rollup/rollup.config.dev.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ const devBuild = {
2121
include: 'src/**',
2222
},
2323
plugins: [
24-
babel({babelHelpers: 'bundled'}),
2524
json(),
25+
babel({babelHelpers: 'bundled'}),
2626
resolve(),
2727
commonjs(),
2828
typescript({
@@ -55,6 +55,7 @@ const declarationsBuild = {
5555
include: 'src/**',
5656
},
5757
plugins: [
58+
json(),
5859
typescript({
5960
tsconfigOverride: {
6061
compilerOptions: {

packages/core/rollup/rollup.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ const declarationsBuild = {
153153
},
154154
],
155155
plugins: [
156+
json(),
156157
typescript({
157158
tsconfigOverride: {
158159
compilerOptions: {

0 commit comments

Comments
 (0)