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
1 parent
f5cb63d
commit e064d19
Showing
9 changed files
with
81 additions
and
83 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 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
32 changes: 0 additions & 32 deletions
32
examples/history-sync-transit/src/components/Counter/index.tsx
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
examples/history-sync-transit/src/components/Textfield/index.module.css
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
examples/history-sync-transit/src/components/Textfield/index.tsx
This file was deleted.
Oops, something went wrong.
5 changes: 3 additions & 2 deletions
5
...t/src/components/Counter/index.module.css → ...components/ViewStateForm/index.module.css
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.wrapper { | ||
.row { | ||
display: flex; | ||
justify-content: space-between; | ||
width: 200px; | ||
} | ||
margin: 0; | ||
} |
37 changes: 37 additions & 0 deletions
37
examples/history-sync-transit/src/components/ViewStateForm/index.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { custom } from '@recoiljs/refine' | ||
import { atom, useRecoilState } from 'recoil' | ||
import { syncEffect } from 'recoil-sync' | ||
|
||
import styles from './index.module.css' | ||
|
||
export class ViewState { | ||
constructor( | ||
public active: boolean, | ||
public pos: [number, number], | ||
) {} | ||
} | ||
|
||
const viewStateChecker = custom(x => x instanceof ViewState ? x : null); | ||
const viewState = atom<ViewState>({ | ||
key: 'viewState', | ||
default: new ViewState(true, [1, 2]), | ||
effects: [syncEffect({ storeKey: 'history-transit-store', refine: viewStateChecker })], | ||
}) | ||
|
||
export const ViewStateForm: React.FC = () => { | ||
const [state, setState] = useRecoilState(viewState) | ||
const toggleActive = () => setState(new ViewState(!state.active, state.pos)) | ||
const incrementPos = () => setState(new ViewState(state.active, [state.pos[0] + 1, state.pos[1] + 1])) | ||
|
||
return ( | ||
<div> | ||
<div className={styles.row}> | ||
active: <input type="checkbox" checked={state.active} onChange={toggleActive} /> | ||
</div> | ||
<div className={styles.row}> | ||
<div>pos: { JSON.stringify(state.pos) }</div> | ||
<button onClick={incrementPos}>increment</button> | ||
</div> | ||
</div> | ||
) | ||
} |