Skip to content

Comments

move to reatom#1

Open
Laniman wants to merge 44 commits intoreatomfrom
master
Open

move to reatom#1
Laniman wants to merge 44 commits intoreatomfrom
master

Conversation

@Laniman
Copy link
Owner

@Laniman Laniman commented Feb 19, 2024

No description provided.

return f.toString();
}
}),
makeSelected: (ctx: Ctx) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to wrap all methods to action

Comment on lines +17 to +44
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;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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"),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reatom name convention is separate names by dot (.).

Suggested change
x: atom(x, "circle-x"),
x: atom(x, "circle.x"),

.spy(dbAtom)
.filter(
([_, x]) =>
x.toLowerCase().indexOf(ctx.spy(prefixAtom).toLowerCase()) !== -1,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the getter outside of the loop (just a good practice)

Comment on lines +37 to +46
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)];
});
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make the changable value atoms to simplify the change code

ctx.get(dbAtom).find(([i]) => i === id)?.[1](ctx, ctx.get(nameAtom))

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here is the corrected version with handleUpdate not working

https://github.com/Laniman/reatom/blob/751-7guis-example/examples/7guis/src/guis/crud.tsx

Copy link
Owner Author

@Laniman Laniman Feb 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

figured it out
I should have used ctx.spy in

<option key={id} value={id}>
  {ctx.spy(x)}
</option>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants