-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b05b2b3
Showing
13 changed files
with
251 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
node_modules | ||
bower_components | ||
coverage | ||
.DS_Store | ||
.idea | ||
.vscode | ||
|
||
# vscode localhistory | ||
.history | ||
dist | ||
|
||
# package manager | ||
npm-debug.log | ||
yarn.lock | ||
package-lock.json | ||
pnpm-lock.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.idea | ||
.DS_Store | ||
**/npm-debug.log | ||
**/node_modules | ||
test | ||
__tests__ | ||
src | ||
build | ||
docs | ||
gulpfile.js | ||
|
||
.editorconfig | ||
.prettierrc | ||
Gemfile | ||
jest.config.js | ||
jest.setup.js | ||
LICENSE.txt | ||
Rakefile | ||
express.js | ||
.babelrc | ||
.vscode | ||
.release-it.json | ||
|
||
|
||
# vscode localhistory | ||
.history | ||
.release-it.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"trailingComma": "none", | ||
"arrowParens": "always", | ||
"printWidth": 100, | ||
"bracketSpacing": true, | ||
"jsxBracketSameLine": true, | ||
"tabWidth": 2, | ||
"semi": true, | ||
"singleQuote": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"git": { | ||
"requireCleanWorkingDir": false | ||
}, | ||
"hooks": { | ||
"after:init": ["t2k"], | ||
"after:bump": ["npm run build"], | ||
"after:release": ["npm pkg get name | cnpm sync"] | ||
}, | ||
"github": { | ||
"release": true, | ||
"proxy": "http://127.0.0.1:9090" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 afei <1290657123@qq.com> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# next-react-valtio | ||
> Valtio for react. | ||
[![version][version-image]][version-url] | ||
[![license][license-image]][license-url] | ||
[![size][size-image]][size-url] | ||
[![download][download-image]][download-url] | ||
|
||
## installation | ||
```bash | ||
yarn add @jswork/next-react-valtio | ||
``` | ||
|
||
## usage | ||
```js | ||
import '@jswork/next-react-valtio'; | ||
``` | ||
|
||
```jsx | ||
const InteractiveList = () => { | ||
const { state, store } = nx.$valtio<number[]>([1, 2, 3, 4]); | ||
return ( | ||
<div className="bg-slate-100 p-2"> | ||
<h1>Vite + React</h1> | ||
<nav className="mt-4 flex gap-1 border border-solid p-1"> | ||
<button onClick={() => store.push(state.length + 1)}>添加</button> | ||
<button | ||
onClick={() => { | ||
store.splice(0, state.length, ...['a', 'b', 'c', 'd', 'e']); | ||
}}> | ||
Reset | ||
</button> | ||
</nav> | ||
{state.map((item, index) => ( | ||
<div className="m-2 block border" key={index}> | ||
<span className="bold mr-1">{item}</span> | ||
<button onClick={() => store.splice(index, 1)}>删除</button> | ||
</div> | ||
))} | ||
{state.length === 0 && <div className="m-2 block border">暂无数据</div>} | ||
</div> | ||
); | ||
}; | ||
|
||
export default InteractiveList; | ||
``` | ||
|
||
## license | ||
Code released under [the MIT license](https://github.com/afeiship/next-react-valtio/blob/master/LICENSE.txt). | ||
|
||
[version-image]: https://img.shields.io/npm/v/@jswork/next-react-valtio | ||
[version-url]: https://npmjs.org/package/@jswork/next-react-valtio | ||
|
||
[license-image]: https://img.shields.io/npm/l/@jswork/next-react-valtio | ||
[license-url]: https://github.com/afeiship/next-react-valtio/blob/master/LICENSE.txt | ||
|
||
[size-image]: https://img.shields.io/bundlephobia/minzip/@jswork/next-react-valtio | ||
[size-url]: https://github.com/afeiship/next-react-valtio/blob/master/dist/next-react-valtio.min.js | ||
|
||
[download-image]: https://img.shields.io/npm/dm/@jswork/next-react-valtio | ||
[download-url]: https://www.npmjs.com/package/@jswork/next-react-valtio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require('../src'); | ||
|
||
jest.setTimeout(60 * 1000); | ||
|
||
describe('api.basic test', () => { | ||
test('nx.boilerplatePackage', function () { | ||
console.log('hello next'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const gulp = require('gulp'); | ||
const { NxScripts, CleanRegistry } = require('@jswork/gulp-registry'); | ||
|
||
const task1 = new CleanRegistry(); | ||
const task2 = new NxScripts({ name: 'qs', classify: true }); | ||
|
||
[task1, task2].forEach(gulp.registry); | ||
|
||
gulp.task('default', gulp.series(['clean', 'nx:scripts'])); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
interface NxStatic { | ||
ReactValtio: any; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// https://jestjs.io/docs/en/configuration | ||
module.exports = { | ||
verbose: true, | ||
testRegex: [/\.spec.js/], | ||
//preset: "jest-puppeteer", | ||
automock: false, | ||
moduleNameMapper: { | ||
'^@/(.*)$': '<rootDir>/src/$1' | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"name": "@jswork/next-react-valtio", | ||
"version": "1.0.0", | ||
"description": "Valtio for react.", | ||
"homepage": "https://js.work", | ||
"author": { | ||
"name": "afei", | ||
"email": "1290657123@qq.com" | ||
}, | ||
"scripts": { | ||
"build": "gulp", | ||
"test": "jest", | ||
"start": "node ./express.js", | ||
"release": "release-it" | ||
}, | ||
"main": "dist/index.js", | ||
"module": "dist/index.esm.js", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@babel/core": "^7.21.3", | ||
"@babel/preset-env": "^7.20.2", | ||
"@jswork/gulp-pkg-header": "^1.0.8", | ||
"@jswork/gulp-registry": "^1.0.22", | ||
"@jswork/next": "^1.1.8", | ||
"del": "^6.0.0", | ||
"gulp": "^4.0.2", | ||
"gulp-babel": "^8.0.0", | ||
"gulp-prettier": "^4.0.0", | ||
"gulp-rename": "^2.0.0", | ||
"gulp-replace": "^1.1.4", | ||
"gulp-uglify": "^3.0.2", | ||
"jest": "^29.5.0", | ||
"jest-location-mock": "^1.0.9", | ||
"react": "^18.2.0", | ||
"uglify-save-license": "^0.4.1", | ||
"valtio": "^1.13.0" | ||
}, | ||
"babel": { | ||
"presets": [ | ||
[ | ||
"@babel/preset-env" | ||
] | ||
] | ||
}, | ||
"publishConfig": { | ||
"access": "public", | ||
"registry": "https://registry.npmjs.org" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import nx from '@jswork/next'; | ||
import { proxy, useSnapshot } from 'valtio'; | ||
import { useRef } from 'react'; | ||
|
||
const NxReactValtio = nx.declare('nx.ReactValtio', { | ||
statics: { | ||
init: function () { | ||
nx.$valtio = (initialState) => { | ||
const store = useRef(proxy(initialState)).current; | ||
const state = useSnapshot(store); | ||
return { store, state }; | ||
}; | ||
} | ||
} | ||
}); | ||
|
||
if (typeof module !== 'undefined' && module.exports && typeof wx === 'undefined') { | ||
module.exports = NxReactValtio; | ||
} | ||
|
||
export default NxReactValtio; |