Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release: 1.0.0 Beta #59

Merged
merged 35 commits into from
Feb 16, 2020
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
f9ca045
feat: init beta
alvinhui Feb 11, 2020
fb28ac4
refactor: test and examples
alvinhui Feb 11, 2020
fe0085e
refactor: connect
alvinhui Feb 11, 2020
d5dba50
Merge remote-tracking branch 'origin/release/1.0.0' into release/1.0.…
alvinhui Feb 11, 2020
c5a948e
chore: lint
alvinhui Feb 11, 2020
bebf01b
chore: types
alvinhui Feb 11, 2020
9fc4f33
chore: lint
alvinhui Feb 11, 2020
aec249e
refactor: use Provider to handle initialStates
alvinhui Feb 13, 2020
72aa37a
fix: use this for actions
alvinhui Feb 13, 2020
ea88315
refactor: prevState for effects funcionts and async state for model
alvinhui Feb 13, 2020
a596be5
chore: use transform
alvinhui Feb 14, 2020
5874de9
feat: add memo deps
alvinhui Feb 14, 2020
85cba89
chore: isLoading
alvinhui Feb 14, 2020
8811dc7
chore: delete unnecessary code
alvinhui Feb 14, 2020
26f3b8c
chore: better demo
alvinhui Feb 14, 2020
2f8d1db
chore: better demo
alvinhui Feb 14, 2020
f503eb2
chore: less code
alvinhui Feb 14, 2020
50b38d7
feat: effect state
alvinhui Feb 14, 2020
27ae41f
chore: createModelContainer
alvinhui Feb 14, 2020
f0fca93
chore: lint
alvinhui Feb 14, 2020
94c55fc
refactor: delete this
alvinhui Feb 14, 2020
400939c
chore: rewrite REAMDE
alvinhui Feb 14, 2020
f370e75
feat: initialStates
alvinhui Feb 14, 2020
2906193
refactor: createModel
alvinhui Feb 15, 2020
31832af
refactor: model define
alvinhui Feb 15, 2020
28fd3fc
refactor: actions params
alvinhui Feb 15, 2020
52097f2
refactor: withStore
alvinhui Feb 16, 2020
7b9f8b0
feat: withModel && withModels
alvinhui Feb 16, 2020
1d5190c
refactor: effect to action
alvinhui Feb 16, 2020
a48f178
chore: class && function component
alvinhui Feb 16, 2020
9de838f
chore: lint
alvinhui Feb 16, 2020
5c852ff
feat: withModelActions && withModelActionsState
alvinhui Feb 16, 2020
71255c0
chore: lint
alvinhui Feb 16, 2020
7940a6a
chore: types
alvinhui Feb 16, 2020
a86add4
chore: effect to action
alvinhui Feb 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: isLoading
alvinhui committed Feb 14, 2020
commit 85cba8913dba036854b7f3bf653db2e2601a8d55
21 changes: 11 additions & 10 deletions examples/todos/src/index.tsx
Original file line number Diff line number Diff line change
@@ -26,10 +26,6 @@ class TodoList extends Component<any> {

render() {
const {title, dataSource, customField, effects} = this.props;

const {isLoading} = effects.remove;
console.log('remove isLoading:', isLoading);

return (
<div>
<h2>class: {title}</h2>
@@ -47,7 +43,9 @@ class TodoList extends Component<any> {
/>
{done ? <s>{name}</s> : <span>{name}</span>}
</label>
<button type="submit" onClick={() => this.onRemove(index)}>-</button>
{
effects.remove.isLoading ? ' 删除中...' : <button type="submit" onClick={() => this.onRemove(index)}>-</button>
}
</li>
))}
</ul>
@@ -105,8 +103,10 @@ const TodoListWithStore = store.connect(
// }

function TodoApp() {
const todos = store.useModel('todos');
const [{dataSource}, {refresh, add}] = todos;
const [ state, actions ] = store.useModel('todos');
const {dataSource, effects} = state;
const {refresh, add} = actions;

useEffect(() => {
console.log('TodoApp:action - refresh...');
refresh();
@@ -119,14 +119,15 @@ function TodoApp() {

const noTaskView = <span>no task</span>;
const loadingView = <span>loading...</span>;
const taskView = <TodoListWithStore title="标题" />;
const taskResultView = dataSource.length ? taskView : noTaskView;
const taskView = dataSource.length ? <TodoListWithStore title="标题" /> : (
noTaskView
);

console.log('TodoApp rending... ');
return (
<div>
<h2>Todos</h2>
{taskResultView}
{!effects.refresh.isLoading ? taskView : loadingView}
</div>
);
}
61 changes: 23 additions & 38 deletions examples/todos/src/models/todos.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { delay } from '../utils';

interface Todo {
name: string;
done?: boolean;
}

export interface TodoStore {
dataSource: Todo[];
refresh: () => void;
@@ -28,55 +29,39 @@ const store = {
dataSource: todos,
};
},
addData(prevState, todo) {
return {
dataSource: [...prevState.dataSource, todo],
};
},
removeData(prevState, index) {
prevState.dataSource.splice(index, 1);
return {
...prevState,
};
},
},

effects: {
add(todo, state, actions) {
(this as any).addData(todo);
actions.user.increaseTodos(1);
state.dataSource.push(todo);
(this as any).setDataSource(state.dataSource);
actions.user.setTodos(state.dataSource.length);
},

async refresh(state, actions) {
console.log('effects-refresh');
const dataSource: any[] = await new Promise(resolve =>
setTimeout(() => {
resolve([
{
name: 'react',
},
{
name: 'vue',
done: true,
},
{
name: 'angular',
},
]);
}, 1000),
);
await delay(2000);
const dataSource: any[] = [
{
name: 'react',
},
{
name: 'vue',
done: true,
},
{
name: 'angular',
},
];
actions.todos.setDataSource(dataSource);
actions.user.setTodos(dataSource.length);
},

async remove(index, state, actions) {
await new Promise(resolve =>
setTimeout(() => {
resolve();
}, 1000),
);
actions.todos.removeData(index);
actions.user.reduceTodos(1);
await delay(1000);

state.dataSource.splice(index, 1);
(this as any).setDataSource(state.dataSource);
actions.user.setTodos(state.dataSource.length);
},
},
};
21 changes: 7 additions & 14 deletions examples/todos/src/models/user.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { delay } from '../utils';

export interface User {
name?: string;
age?: number;
@@ -20,14 +22,11 @@ const store = {
},
effects: {
async login(state, actions) {
const dataSource = await new Promise(resolve =>
setTimeout(() => {
resolve({
name: 'Alvin',
age: 18,
});
}, 1000),
);
await delay(1000);
const dataSource = {
name: 'Alvin',
age: 18,
};
const auth = true;
actions.user.setState({
dataSource,
@@ -39,12 +38,6 @@ const store = {
setTodos(prevState, todos: number) {
return { ...prevState, todos };
},
increaseTodos(prevState, value: number) {
return { ...prevState, todos: prevState.todos + value };
},
reduceTodos(prevState, value: number) {
return { ...prevState, todos: prevState.todos - value };
},
setState(prevState, nextState) {
return {
...prevState,
3 changes: 3 additions & 0 deletions examples/todos/src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export async function delay(time) {
return new Promise((resolve) => setTimeout(() => resolve(), time));
}