This repository has been archived by the owner on Nov 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
[WIP] feat: hook-store plugin #432
Open
luhc228
wants to merge
8
commits into
release-next
Choose a base branch
from
feat/hook-store-plugin
base: release-next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4820ca5
feat: init hook-store plugin
luhc228 b95da8b
feat: page store
luhc228 6694c43
feat: page store
luhc228 4aeec4e
Merge branch 'feat/hook-store-plugin' of github.com:ice-lab/ice-next …
luhc228 5644e33
chore: changelog
luhc228 9de1f7a
fix: type error
luhc228 94f892e
chore: rename and update version
luhc228 26c75d4
Merge branch 'release-next' into feat/hook-store-plugin
luhc228 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,8 @@ | ||
import { defineConfig } from '@ice/app'; | ||
import store from '@ice/plugin-hooks-store'; | ||
|
||
export default defineConfig({ | ||
plugins: [ | ||
store(), | ||
], | ||
}); |
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 @@ | ||
{ | ||
"name": "with-hook-store", | ||
"private": true, | ||
"version": "1.0.0", | ||
"scripts": { | ||
"start": "ice start", | ||
"build": "ice build" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"@ice/app": "workspace:*", | ||
"@ice/runtime": "workspace:*" | ||
}, | ||
"devDependencies": { | ||
"@ice/plugin-hooks-store": "workspace:*", | ||
"@types/react": "^18.0.0", | ||
"@types/react-dom": "^18.0.0", | ||
"browserslist": "^4.19.3", | ||
"regenerator-runtime": "^0.13.9" | ||
} | ||
} |
Binary file not shown.
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 @@ | ||
import { defineAppConfig } from 'ice'; | ||
|
||
export default defineAppConfig({}); |
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,23 @@ | ||
import { Meta, Title, Links, Main, Scripts } from 'ice'; | ||
|
||
function Document() { | ||
return ( | ||
<html> | ||
<head> | ||
<meta charSet="utf-8" /> | ||
<link rel="icon" href="/favicon.ico" /> | ||
<meta name="description" content="with-store" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<Meta /> | ||
<Title /> | ||
<Links /> | ||
</head> | ||
<body> | ||
<Main /> | ||
<Scripts /> | ||
</body> | ||
</html> | ||
); | ||
} | ||
|
||
export default Document; |
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,12 @@ | ||
import { useState } from 'react'; | ||
|
||
function useTodo() { | ||
const [todos, setTodos] = useState([{ name: 'ICE', id: 'ICE' }]); | ||
|
||
return { | ||
todos, | ||
setTodos, | ||
}; | ||
} | ||
|
||
export default useTodo; |
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 @@ | ||
import { Link } from 'ice'; | ||
import store from './store'; | ||
|
||
function About() { | ||
const { name, age } = store.useHook('useUser'); | ||
return ( | ||
<> | ||
<div>name: {name}</div> | ||
<div>age: {age}</div> | ||
|
||
<Link to="/">Home</Link> | ||
</> | ||
); | ||
} | ||
|
||
export default About; |
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 @@ | ||
import { Outlet } from 'ice'; | ||
|
||
export default function layout() { | ||
return ( | ||
<> | ||
<Outlet /> | ||
</> | ||
); | ||
} |
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,6 @@ | ||
export default function useUser() { | ||
return { | ||
name: 'ICE 3', | ||
age: 5, | ||
}; | ||
} |
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,4 @@ | ||
import { createStore } from 'ice'; | ||
import useUser from './models/useUser'; | ||
|
||
export default createStore({ useUser }); |
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,28 @@ | ||
import { Link } from 'ice'; | ||
import pageStore from './store'; | ||
import appStore from '@/store'; | ||
|
||
function Home() { | ||
const { todos } = appStore.useHook('useTodo'); | ||
const { count, increment, decrement } = pageStore.useHook('useCounter'); | ||
|
||
return ( | ||
<> | ||
<div> | ||
ToDo List | ||
<ul id="todos"> | ||
{todos.map(todo => (<li key={todo.id}>{todo.name}</li>))} | ||
</ul> | ||
</div> | ||
<div> | ||
<button type="button" onClick={() => increment()}>+</button> | ||
<span>{count}</span> | ||
<button type="button" onClick={() => decrement()}>-</button> | ||
</div> | ||
<Link to="/about">About</Link> | ||
</> | ||
); | ||
} | ||
|
||
|
||
export default Home; |
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,15 @@ | ||
import { useState } from 'react'; | ||
|
||
function useCounter() { | ||
const [count, setCount] = useState(0); | ||
const increment = () => setCount(count + 1); | ||
const decrement = () => setCount(count - 1); | ||
|
||
return { | ||
count, | ||
increment, | ||
decrement, | ||
}; | ||
} | ||
|
||
export default useCounter; |
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,4 @@ | ||
import { createStore } from 'ice'; | ||
import useCounter from './models/useCounter'; | ||
|
||
export default createStore({ useCounter }); |
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,4 @@ | ||
import { createStore } from 'ice'; | ||
import useTodo from './models/useTodo'; | ||
|
||
export default createStore({ useTodo }); |
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,32 @@ | ||
{ | ||
"compileOnSave": false, | ||
"buildOnSave": false, | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"outDir": "build", | ||
"module": "esnext", | ||
"target": "es6", | ||
"jsx": "react-jsx", | ||
"moduleResolution": "node", | ||
"allowSyntheticDefaultImports": true, | ||
"lib": ["es6", "dom"], | ||
"sourceMap": true, | ||
"allowJs": true, | ||
"rootDir": "./", | ||
"forceConsistentCasingInFileNames": true, | ||
"noImplicitReturns": true, | ||
"noImplicitThis": true, | ||
"noImplicitAny": false, | ||
"importHelpers": true, | ||
"strictNullChecks": true, | ||
"suppressImplicitAnyIndexErrors": true, | ||
"noUnusedLocals": true, | ||
"skipLibCheck": true, | ||
"paths": { | ||
"@/*": ["./src/*"], | ||
"ice": [".ice"] | ||
} | ||
}, | ||
"include": ["src", ".ice", "ice.config.*"], | ||
"exclude": ["node_modules", "build", "public"] | ||
} |
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,5 @@ | ||
# CHANGELOG | ||
|
||
## 1.0.0 | ||
|
||
- feat: init plugin |
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 @@ | ||
# @ice/plugin-hooks-store | ||
|
||
A plugin of lightweight React Hooks state management used in framework `ICE`. | ||
|
||
## Usage | ||
|
||
```ts | ||
import { defineConfig } from '@ice/app'; | ||
import store from '@ice/plugin-hooks-store'; | ||
|
||
export default defineConfig({ | ||
plugins: [ | ||
store(), | ||
], | ||
}); | ||
``` |
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,56 @@ | ||
{ | ||
"name": "@ice/plugin-hooks-store", | ||
"version": "1.0.0", | ||
"description": "A plugin of lightweight React Hooks state management based on @ice/hooks-store.", | ||
"license": "MIT", | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"types": "./esm/index.d.ts", | ||
"import": "./esm/index.js", | ||
"default": "./esm/index.js" | ||
}, | ||
"./runtime": { | ||
"types": "./esm/runtime.d.ts", | ||
"import": "./esm/runtime.js", | ||
"default": "./esm/runtime.js" | ||
}, | ||
"./api": { | ||
"types": "./esm/api.d.ts", | ||
"import": "./esm/api.js", | ||
"default": "./esm/api.js" | ||
} | ||
}, | ||
"main": "./esm/index.js", | ||
"types": "./esm/index.d.ts", | ||
"files": [ | ||
"esm", | ||
"!esm/**/*.map" | ||
], | ||
"dependencies": { | ||
"@ice/hooks-store": "^1.0.0-alpha.0", | ||
"fast-glob": "^3.2.11", | ||
"micromatch": "^4.0.5" | ||
}, | ||
"devDependencies": { | ||
"@ice/types": "^1.0.0", | ||
"@types/react": "^18.0.0", | ||
"@types/react-dom": "^18.0.0", | ||
"@types/micromatch": "^4.0.2", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"regenerator-runtime": "^0.13.9" | ||
}, | ||
"peerDependencies": { | ||
"react": "^18.0.0", | ||
"react-dom": "^18.0.0" | ||
}, | ||
"repository": { | ||
"type": "http", | ||
"url": "https://github.com/ice-lab/ice-next/tree/master/packages/plugin-hook-store" | ||
}, | ||
"scripts": { | ||
"watch": "tsc -w", | ||
"build": "tsc" | ||
} | ||
} |
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 @@ | ||
/** | ||
* This file which is imported by the runtime.tsx, is to avoid TS error. | ||
*/ | ||
import { createStore } from '@ice/hooks-store'; | ||
|
||
const models = {}; | ||
|
||
const store: ReturnType<typeof createStore> = createStore(models); | ||
|
||
export default store; |
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 @@ | ||
export { createStore } from '@ice/hooks-store'; |
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,2 @@ | ||
export const PAGE_STORE_MODULE = '__PAGE_STORE__'; | ||
export const PAGE_STORE_PROVIDER = '__PAGE_STORE_PROVIDER__'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个 API 名称不修改吗