-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: fix Model types * fix: fix types error * chore: commit examples to sync with lockfile * fix: fix ci
- Loading branch information
Showing
31 changed files
with
16,095 additions
and
265 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
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
This file was deleted.
Oops, something went wrong.
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,13 @@ | ||
import Footer from './Footer'; | ||
import AddTodo from '../containers/AddTodo'; | ||
import VisibleTodoList from '../containers/VisibleTodoList'; | ||
|
||
const App = () => ( | ||
<div> | ||
<AddTodo /> | ||
<VisibleTodoList /> | ||
<Footer /> | ||
</div> | ||
); | ||
|
||
export default App; |
1 change: 0 additions & 1 deletion
1
examples/todos/src/components/Footer.js → examples/todos/src/components/Footer.tsx
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
This file was deleted.
Oops, something went wrong.
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,20 @@ | ||
import { PropsWithChildren } from 'react'; | ||
|
||
interface Props { | ||
active: boolean; | ||
onClick: () => void; | ||
} | ||
|
||
const Link = ({ active, children, onClick }: PropsWithChildren<Props>) => ( | ||
<button | ||
onClick={onClick} | ||
disabled={active} | ||
style={{ | ||
marginLeft: '4px', | ||
}} | ||
> | ||
{children} | ||
</button> | ||
); | ||
|
||
export default Link; |
This file was deleted.
Oops, something went wrong.
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,20 @@ | ||
import { PropsWithChildren } from "react" | ||
|
||
interface Props { | ||
text: string, | ||
completed: boolean, | ||
onClick: () => void | ||
} | ||
|
||
const Todo = ({ onClick, completed, text }: PropsWithChildren<Props>) => ( | ||
<li | ||
onClick={onClick} | ||
style={{ | ||
textDecoration: completed ? 'line-through' : 'none' | ||
}} | ||
> | ||
{text} | ||
</li> | ||
) | ||
|
||
export default Todo |
This file was deleted.
Oops, something went wrong.
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,24 @@ | ||
import Todo from './Todo' | ||
import todos from '../models/todos' | ||
import type {Todo as TTodo} from '../models/todos' | ||
import { GetModelActions } from '@modern-js-reduck/react' | ||
import { PropsWithChildren } from 'react' | ||
|
||
interface Props { | ||
todos: TTodo[], | ||
toggleTodo: GetModelActions<typeof todos>['toggleTodo'] | ||
} | ||
|
||
const TodoList = ({ todos, toggleTodo }: PropsWithChildren<Props>) => ( | ||
<ul> | ||
{todos.map(todo => | ||
<Todo | ||
key={todo.id} | ||
{...todo} | ||
onClick={() => toggleTodo(todo.id)} | ||
/> | ||
)} | ||
</ul> | ||
) | ||
|
||
export default TodoList |
This file was deleted.
Oops, something went wrong.
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 @@ | ||
import { useRef } from 'react'; | ||
import { useModel } from '@modern-js-reduck/react'; | ||
import todos from '../models/todos'; | ||
|
||
const AddTodo = () => { | ||
const [, actions] = useModel(todos); | ||
|
||
// won't re-render when todos state change, because the state selector always return null | ||
// const [,actions] = useModel(todos, (state) => null); | ||
|
||
const inputRef = useRef<HTMLInputElement>(null); | ||
|
||
return ( | ||
<div> | ||
<form | ||
onSubmit={e => { | ||
e.preventDefault(); | ||
if (!inputRef.current?.value.trim()) { | ||
return; | ||
} | ||
actions.addTodo(inputRef.current.value); | ||
inputRef.current.value = ''; | ||
}} | ||
> | ||
<input ref={inputRef} /> | ||
<button type="submit">Add Todo</button> | ||
</form> | ||
</div> | ||
); | ||
}; | ||
|
||
export default AddTodo; |
This file was deleted.
Oops, something went wrong.
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 { useModel } from '@modern-js-reduck/react'; | ||
import { PropsWithChildren } from 'react'; | ||
import Link from '../components/Link'; | ||
import todos, { VisibilityFilters } from '../models/todos'; | ||
|
||
interface Props { | ||
filter: VisibilityFilters; | ||
} | ||
|
||
const FilterLink = (props: PropsWithChildren<Props>) => { | ||
const { filter, children } = props; | ||
const [{ visibilityFilter }, { setVisibilityFilter }] = useModel(todos); | ||
|
||
// won't re-render when only the `data` slice of state change, | ||
// because the state selector lets `FilterLink` only subscribe the `visibilityFilter` slice of the state | ||
// const [visibilityFilter, {setVisibilityFilter}] = useModel(todos, (state) => state.visibilityFilter) | ||
|
||
return ( | ||
<Link | ||
active={visibilityFilter === filter} | ||
onClick={() => setVisibilityFilter(filter)} | ||
> | ||
{children} | ||
</Link> | ||
); | ||
}; | ||
|
||
export default FilterLink; |
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
This file was deleted.
Oops, something went wrong.
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 @@ | ||
import ReactDOM from 'react-dom/client'; | ||
import { Provider } from '@modern-js-reduck/react'; | ||
import App from './components/App'; | ||
|
||
const root = ReactDOM.createRoot(document.getElementById('root')!); | ||
root.render( | ||
<Provider> | ||
<App /> | ||
</Provider>, | ||
); |
Oops, something went wrong.