Skip to content

Commit 5d8cd12

Browse files
Merge pull request #1 from nexpy-io/feat/pick-context-selector-source-code
Feat/pick context selector source code
2 parents 673ad2f + 86a0647 commit 5d8cd12

13 files changed

Lines changed: 5826 additions & 421 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,5 @@ sketch
179179
!.vscode/*.code-snippets
180180

181181
# End of https://www.toptal.com/developers/gitignore/api/node,git,visualstudiocode,react
182+
183+
src/native

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ commitlint.config.js
1414
rollup.config.js
1515
tsconfig.json
1616
yarn.lock
17+
automation

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ const MyComponent = () => {
163163

164164
#### useContextUpdate
165165

166-
This hook returns an update function that accepts a thunk function
166+
This hook returns an update function that accepts a thunk function.
167167

168168
Use this for a function that will change a value in
169169
[Concurrent Mode](https://reactjs.org/docs/concurrent-mode-intro.html).
@@ -182,7 +182,15 @@ const MyComponent = () => {
182182

183183
#### BridgeProvider
184184

185-
This is a Provider component for bridging multiple react roots
185+
This is a Provider component for bridging multiple react roots.
186+
187+
#### Context
188+
189+
The special context created by createContext hook.
190+
191+
#### Provider
192+
193+
The provider you need to use to apply the context.
186194

187195
##### Parameters
188196

@@ -221,7 +229,7 @@ const App = () => {
221229

222230
#### useBridgeValue
223231

224-
This hook return a value for BridgeProvider
232+
This hook return a value for BridgeProvider.
225233

226234
## Limitations
227235

automation/precompile-native.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
rm -r src/native
2+
mkdir src/native
3+
cp src/index.tsx src/native/index.tsx
4+
cp src/contextSelector.ts src/native/contextSelector.ts
5+
cp src/batchedUpdates.native.ts src/native/batchedUpdates.ts

examples/cats.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const CatsPetted = () => {
4242
return (
4343
<div>
4444
<p>Petted cats: {catsPettedNumber}</p>
45-
<button onClick={() => setter(state => state + 1)}>Add one</button>
45+
<button onClick={() => setter(prevState => prevState + 1)}>Add one</button>
4646
</div>
4747
)
4848
}
@@ -54,7 +54,7 @@ const CurrentCats = () => {
5454
return (
5555
<div>
5656
<p>Current cats: {currentCatsNumber}</p>
57-
<button onClick={() => setter(state => state + 1)}>Add one</button>
57+
<button onClick={() => setter(prevState => prevState + 1)}>Add one</button>
5858
</div>
5959
)
6060
}

package.json

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,23 @@
44
"keywords": [
55
"context-api",
66
"react",
7-
"nexpy"
7+
"nexpy",
8+
"context",
9+
"hooks"
810
],
9-
"version": "1.0.0",
11+
"version": "1.0.1",
1012
"license": "MIT",
11-
"main": "dist/index.js",
1213
"author": "AllanOliveiraM",
13-
"dependencies": {
14-
"use-context-selector": "^1.3.9"
15-
},
14+
"main": "./dist/index.js",
15+
"module": "./dist/index.js",
16+
"react-native": "./dist/index.native.js",
17+
"types": "./dist/index.d.ts",
18+
"dependencies": {},
1619
"scripts": {
1720
"husky:install": "husky install",
18-
"build": "rollup -c",
19-
"start": "rollup -c -w",
21+
"precompile:native": ". automation/precompile-native.sh",
22+
"build": "yarn --silent precompile:native && rollup -c",
23+
"start": "yarn --silent precompile:native && rollup -c -w",
2024
"commit": "npx git-cz",
2125
"type-check": "tsc --project tsconfig.json --pretty --noEmit",
2226
"prettier": "prettier --loglevel warn --write .",
@@ -29,9 +33,12 @@
2933
"@commitlint/config-conventional": "^15.0.0",
3034
"@rollup/plugin-commonjs": "^21.0.1",
3135
"@rollup/plugin-node-resolve": "^13.0.6",
36+
"@testing-library/react": "^12.1.2",
37+
"@types/jest": "^27.4.0",
3238
"@types/node": "^16.11.11",
3339
"@types/react": "^17.0.0",
3440
"@types/react-dom": "^17.0.0",
41+
"@types/react-native": "^0.66.15",
3542
"@typescript-eslint/eslint-plugin": "^5.5.0",
3643
"@typescript-eslint/parser": "^5.5.0",
3744
"commitlint": "^15.0.0",
@@ -46,14 +53,17 @@
4653
"eslint-plugin-react": "^7.27.1",
4754
"eslint-plugin-react-hooks": "^4.3.0",
4855
"husky": "^7.0.4",
56+
"jest": "^27.4.7",
4957
"lint-staged": "^12.1.2",
5058
"prettier": "^2.5.0",
5159
"react": "^17.0.2",
5260
"react-dom": "^17.0.2",
61+
"react-native": "^0.67.1",
5362
"rollup": "^2.62.0",
63+
"rollup-plugin-terser": "^7.0.2",
5464
"rollup-plugin-typescript2": "^0.31.1",
55-
"rollup-plugin-uglify": "^6.0.4",
5665
"scheduler": "^0.20.2",
66+
"ts-jest": "^27.1.3",
5767
"typescript": "^4.5.2"
5868
},
5969
"peerDependencies": {
@@ -62,6 +72,18 @@
6272
"react-native": "*",
6373
"scheduler": ">=0.19.0"
6474
},
75+
"peerDependenciesMeta": {
76+
"react-dom": {
77+
"optional": true
78+
},
79+
"react-native": {
80+
"optional": true
81+
}
82+
},
83+
"jest": {
84+
"testEnvironment": "jsdom",
85+
"preset": "ts-jest/presets/js-with-ts"
86+
},
6587
"config": {
6688
"commitizen": {
6789
"path": "./node_modules/cz-conventional-changelog"

rollup.config.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
11
import typescript from 'rollup-plugin-typescript2'
22
import commonjs from '@rollup/plugin-commonjs'
3-
import { uglify } from 'rollup-plugin-uglify'
3+
import { terser } from 'rollup-plugin-terser'
44

55
import packageSettings from './package.json'
66

7-
export default {
8-
input: 'src/index.tsx',
9-
output: [
10-
{
7+
export default [
8+
{
9+
input: 'src/index.tsx',
10+
output: {
1111
file: packageSettings.main,
1212
format: 'cjs',
1313
exports: 'named',
1414
sourcemap: true,
1515
strict: true,
1616
},
17-
],
18-
plugins: [typescript(), commonjs(), uglify()],
19-
external: ['react', 'react-dom', 'react/jsx-runtime', 'use-context-selector'],
20-
}
17+
plugins: [typescript(), commonjs(), terser()],
18+
external: ['react', 'react-native', 'react-dom', 'react/jsx-runtime', 'scheduler'],
19+
},
20+
{
21+
input: 'src/native/index.tsx',
22+
output: {
23+
file: `${packageSettings.main.replace('.js', '')}.native.js`,
24+
format: 'cjs',
25+
exports: 'named',
26+
sourcemap: true,
27+
strict: true,
28+
},
29+
plugins: [typescript(), commonjs(), terser()],
30+
external: ['react', 'react-native', 'react-dom', 'react/jsx-runtime', 'scheduler'],
31+
},
32+
]

src/batchedUpdates.native.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { unstable_batchedUpdates as batchedUpdates } from 'react-native'

src/batchedUpdates.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { unstable_batchedUpdates as batchedUpdates } from 'react-dom'

0 commit comments

Comments
 (0)