-
Notifications
You must be signed in to change notification settings - Fork 11
simplify patterns for charm references in cell #1799
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
simplify patterns for charm references in cell #1799
Conversation
cell instead of calling cell() although i still create isInitialized from cell(), not sure how to turn that into a default via the json schema if thats possible. improved comments
| isInitialized: Cell<boolean>; | ||
| } | ||
| const RecipeStateSchema = toSchema<RecipeState>(); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
im not sure how to get isInitialized to get defaulted so that i dont have to create it with cell(), i tried passing a default here:
+const RecipeStateSchema = toSchema<RecipeState>({
+ default: { isInitialized: false },
+});
but when i call the handler, it still requires the parameter, even if i made it optional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you want your initial declaration to be:
interface RecipeState {
charm: any;
cellRef: Cell<{ charm: any }>;
isInitialized: Cell<Default<boolean, false>>;
}Edit: actually, this may not be what you want, since you don't want to have to initialize it as a cell.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To merge options, I think you would have wanted:
{
"properties": {
"isInitialized": {
"default": false
}
}
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Default<boolean, false> option would work. But it really does is replace undefined with false, so if your code says if (isInitialized.get()) it doesn't matter.
And yes, you have to call the lift with a cell, but it can be myLiftedFunction({ foo, bar, isInitalized: cell(false)}) or technically just cell().
The underlying reason is an asymmetry we should anyway resolve: When a recipe gets static data, it just makes a new cell, so it's read/write, but for lift static inputs (and hence also defaults) are read-only. We should change that, and then you wouldn't need the cell creation in this case (<=> the cell is created implicitly by the input that wasn't passed in).
removed uneccesasary lifts, use Default to create cell instead of calling cell() although i still create isInitialized from cell(), not sure how to turn that into a default via the json schema if thats possible.
improved comments
Summary by cubic
Simplifies the charm-in-cell pattern by replacing the setup lift with a Default-backed recipe state and wrapping the stored charm in { charm }. This reduces complexity and fixes navigation and loop issues. Addresses Linear CT-909.
Refactors
Bug Fixes