Skip to content

Implement Model Identity Keys #345

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

Merged
merged 20 commits into from
Apr 17, 2021
Merged

Implement Model Identity Keys #345

merged 20 commits into from
Apr 17, 2021

Conversation

rmorshea
Copy link
Collaborator

@rmorshea rmorshea commented Apr 3, 2021

closes: #330

See the React docs for more info on this type of feature: https://reactjs.org/docs/lists-and-keys.html

This will allow the layout to know whether or not the identity of any particular model has changed, and thus, whether or not its state should be replaced.

  • Add test verifying that state is preserved for keyed component
  • Add test checking that effects behavior correctly for keyed components

@rmorshea rmorshea force-pushed the keys branch 7 times, most recently from a1b3a06 to a17a57e Compare April 9, 2021 04:52
@rmorshea rmorshea marked this pull request as ready for review April 9, 2021 04:52
@rmorshea rmorshea force-pushed the keys branch 5 times, most recently from 1ac1c7a to 1e84aab Compare April 9, 2021 08:27
rmorshea added 15 commits April 13, 2021 22:47
also add comment about why we inject extra validation in
debug mode
all makes event handler targets deterministic
based on keys and child indices
At the moment, whenever a particular branch of a layout is
updated, all the state (i.e. hooks and event handlers) that
live within that branch are thrown away and reconstructed.
Given IDOM’s current implementation for Layout this is
unavoidable. To resolve this issue, we need to add a concept
of “keys” which can be used to indicate the identity of an
element within the layout structure. For example, if you have
a list of elements that get re-ordered when a button is
pressed, their state should be preserved, and reassigned to
their new location in the layout.

By default React requires keys to be used to communicate
element identity whenever the order or number of simbling
elements can change. While there are clear performance
benefits for adhering to this stipulation, it’s often
confusing for new developers. React has the further advantage
of the JSX syntax, which makes it easier for the program to
determine exactly when keys must be supplied by the user. To
make the experience for new users simpler, and due to a lack
of inforcement via JSX, IDOM will be to assume that any
element without a key is new. Thus, for IDOM, keys will
primarilly be a tool for optimization rather than a functional
requirement.
this needs to be cleaned up now that we know what the bugs
were
@rmorshea rmorshea merged commit e3a11bf into main Apr 17, 2021
@rmorshea rmorshea deleted the keys branch April 17, 2021 21:05
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.

Stale event handlers with frequent state updates
1 participant