Conversation
add memo for CircleComp read circlesAtom inside CircleDrawerPure
| return f.toString(); | ||
| } | ||
| }), | ||
| makeSelected: (ctx: Ctx) => { |
There was a problem hiding this comment.
It would be good to wrap all methods to action
| export const CircleDrawerTraditional = reatomComponent(({ ctx }) => { | ||
| const handleAddCircle = useAction(addCircleAction); | ||
| const handleMouseMove = useAction(mouseMoveAction); | ||
| const handleMouseLeave = useAction(mouseLeaveAction); | ||
| const handleContextMenu = useAction(contextMenuAction); | ||
| const handleChangeDiameter = useAction(changeDiameterAction); | ||
| const handleStopChangeDiameter = useAction(stopChangeDiameterAction); | ||
| const handleAdjust = useAction(adjustAction); | ||
| const getClosest = useAction(getClosestAction); | ||
|
|
||
| return ( | ||
| <CircleDrawerPure | ||
| inContextMode={inContextModeAtom} | ||
| onMouseMove={handleMouseMove} | ||
| onMouseLeave={handleMouseLeave} | ||
| onCanvasClick={handleAddCircle} | ||
| onCircleClick={handleContextMenu} | ||
| onAdjustClick={handleAdjust} | ||
| getClosest={getClosest} | ||
| onDiameterChange={handleChangeDiameter} | ||
| onDiameterRelease={handleStopChangeDiameter} | ||
| onUndo={ctx.bind(circlesAtom.undo)} | ||
| onRedo={ctx.bind(circlesAtom.redo)} | ||
| canUndo={ctx.spy(circlesAtom.isUndoAtom)} | ||
| canRedo={ctx.spy(circlesAtom.isRedoAtom)} | ||
| /> | ||
| ); | ||
| }) as React.FC; |
There was a problem hiding this comment.
| export const CircleDrawerTraditional = reatomComponent(({ ctx }) => { | |
| const handleAddCircle = useAction(addCircleAction); | |
| const handleMouseMove = useAction(mouseMoveAction); | |
| const handleMouseLeave = useAction(mouseLeaveAction); | |
| const handleContextMenu = useAction(contextMenuAction); | |
| const handleChangeDiameter = useAction(changeDiameterAction); | |
| const handleStopChangeDiameter = useAction(stopChangeDiameterAction); | |
| const handleAdjust = useAction(adjustAction); | |
| const getClosest = useAction(getClosestAction); | |
| return ( | |
| <CircleDrawerPure | |
| inContextMode={inContextModeAtom} | |
| onMouseMove={handleMouseMove} | |
| onMouseLeave={handleMouseLeave} | |
| onCanvasClick={handleAddCircle} | |
| onCircleClick={handleContextMenu} | |
| onAdjustClick={handleAdjust} | |
| getClosest={getClosest} | |
| onDiameterChange={handleChangeDiameter} | |
| onDiameterRelease={handleStopChangeDiameter} | |
| onUndo={ctx.bind(circlesAtom.undo)} | |
| onRedo={ctx.bind(circlesAtom.redo)} | |
| canUndo={ctx.spy(circlesAtom.isUndoAtom)} | |
| canRedo={ctx.spy(circlesAtom.isRedoAtom)} | |
| /> | |
| ); | |
| }) as React.FC; | |
| export const CircleDrawerTraditional = reatomComponent(({ ctx }) => ( | |
| <CircleDrawerPure | |
| inContextMode={inContextModeAtom} | |
| onMouseMove={ctx.bind(mouseMoveAction)} | |
| onMouseLeave={ctx.bind(mouseLeaveAction)} | |
| onCanvasClick={ctx.bind(addCircleAction)} | |
| onCircleClick={ctx.bind(contextMenuAction)} | |
| onAdjustClick={ctx.bind(adjustAction)} | |
| getClosest={ctx.bind(getClosestAction)} | |
| onDiameterChange={ctx.bind(changeDiameterAction)} | |
| onDiameterRelease={ctx.bind(stopChangeDiameterAction)} | |
| onUndo={ctx.bind(circlesAtom.undo)} | |
| onRedo={ctx.bind(circlesAtom.redo)} | |
| canUndo={ctx.spy(circlesAtom.isUndoAtom)} | |
| canRedo={ctx.spy(circlesAtom.isRedoAtom)} | |
| /> | |
| )); |
| diameter: number, | ||
| ): Circle => { | ||
| const circle: Circle = { | ||
| x: atom(x, "circle-x"), |
There was a problem hiding this comment.
Reatom name convention is separate names by dot (.).
| x: atom(x, "circle-x"), | |
| x: atom(x, "circle.x"), |
| .spy(dbAtom) | ||
| .filter( | ||
| ([_, x]) => | ||
| x.toLowerCase().indexOf(ctx.spy(prefixAtom).toLowerCase()) !== -1, |
There was a problem hiding this comment.
Move the getter outside of the loop (just a good practice)
| const id = ctx.get(selectedAtom); | ||
| const index = ctx.get(dbAtom).findIndex(([i]) => i === id); | ||
| if (index === -1) return; | ||
|
|
||
| handleDelete = () => { | ||
| const id = this.selected.get() | ||
| const index = this.db.findIndex(([i]) => i === id) | ||
| if (index === -1) return | ||
| this.db.splice(index, 1) | ||
| } | ||
| dbAtom(ctx, (prev) => { | ||
| return prev.map((item, i) => { | ||
| if (i !== index) return item; | ||
| return [uuid(), ctx.get(nameAtom)]; | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Make the changable value atoms to simplify the change code
ctx.get(dbAtom).find(([i]) => i === id)?.[1](ctx, ctx.get(nameAtom))There was a problem hiding this comment.
I tried to do it this way and now there is no re-rendering when handleUpdate is called, because the db array is not changed - the name value in the atom is changed
how can I fix this?
There was a problem hiding this comment.
here is the corrected version with handleUpdate not working
https://github.com/Laniman/reatom/blob/751-7guis-example/examples/7guis/src/guis/crud.tsx
There was a problem hiding this comment.
figured it out
I should have used ctx.spy in
<option key={id} value={id}>
{ctx.spy(x)}
</option>
No description provided.