Skip to content

Conversation

@ellyxir
Copy link
Contributor

@ellyxir ellyxir commented Sep 18, 2025

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

    • Replace createCellRef lift with recipe state: cellRef: Default<{ charm: any }, { charm: undefined }>.
    • Store charm as { charm } and update storeCharmAndNavigate and handlers to use Cell<{ charm: any }>.
    • Improve comments and simplify derive/UI for empty states.
  • Bug Fixes

    • goToStoredCharm now navigates to cellRef.get().charm.
    • Prevent reactivity loops via per-invocation isInitialized.
    • Avoids cell-in-cell pointer issues by not storing a charm directly.

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
@ellyxir ellyxir self-assigned this Sep 18, 2025
@linear
Copy link

linear bot commented Sep 18, 2025

@ellyxir ellyxir marked this pull request as ready for review September 18, 2025 17:46
isInitialized: Cell<boolean>;
}
const RecipeStateSchema = toSchema<RecipeState>();

Copy link
Contributor Author

@ellyxir ellyxir Sep 18, 2025

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.

Copy link
Contributor

@ubik2 ubik2 Sep 18, 2025

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.

Copy link
Contributor

@ubik2 ubik2 Sep 18, 2025

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
     }
  }
}

Copy link
Contributor

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).

@ellyxir ellyxir merged commit 2188232 into main Sep 19, 2025
7 checks passed
@ellyxir ellyxir deleted the ellyse/ct-909-simplify-charms-in-reftsx-patterns branch September 19, 2025 19:54
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.

4 participants