-
-
Notifications
You must be signed in to change notification settings - Fork 408
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
tracked-built-ins built-in #1068
base: master
Are you sure you want to change the base?
Conversation
Notes from first discussing of this proposal in RFC review:
|
tracked-storage-primitive in implementation here: emberjs/ember.js#20814 |
related to non-reactive entries for array and hash: #1070 ( |
Great work on this RFC! I’d like to propose a utility function, such as reactive, that could create the appropriate tracked data structure based on the input type. This could simplify the process of creating tracked values and make the API more flexible. For example, if you pass an object to the reactive function, it would return a import { reactive } from '@ember/reactive';
const trackedObj = reactive({ key: 'value' }); // returns TrackedObject
const trackedArr = reactive([1, 2, 3]); // returns TrackedArray Additionally, I’d suggest reconsidering the naming of |
realized that i don't need tracked-storage-primitives or cells to implement this. PR here, work in progress: glimmerjs/glimmer-vm#1713. By skipping that intermediary user-land abstraction, the TrackedArray implementation would likely be even faster. (implementation happening in glimmer-vm, so that glimmer-vm can implement keywords that build on these structures) |
All tests are ported over to glimmer-vm now -- tho I (re)learned that glimmer-vm doesn't have each-in, so I skipped those tests for now. Now that the infra is ported for quickly testing collection reactivity, porting over Object, Map, Set, WeakMap, WeakSet will be trivial. |
Hello! |
EmberArray should not be used. TrackedArray is preferred and is the way forward. This was addressed in the original RFC for |
Thanks for your answer and for clarification. Considering that, maybe you should consider deprecating EmberArray usage or at least update API documentation to signify TrackedArray should be used instead. |
We are certainly working towards that. |
I second that. Compared to other frameworks, which use "one" function to do that.
And then ember:
where one might say, that ember is really trying hard not wanting to be used... and I wouldn't disagree. My preference would be with one |
implementing a
and that's it? IF we say only primitives, objects, and arrays, what is the justification for omitting maps/sets and their weak variants? less used? What do we say about the future planned reactive data structures? (which are planned under separate imports as well) What do folks think? |
my hunch was to accept anything "native" to js. Then I looked what svelte is accepting, which comes close I'd say: https://github.com/sveltejs/svelte/blob/main/packages/svelte/src/ambient.d.ts - I think that's what I'd probably expect (more like gut feeling here), dunno if svelte has an RFC for that. My questions:
|
Thanks for providing those links! that was helpful 💪
I think what you're proposing does, but the main thing that this RFC is concerned about is public (not quite low-level) API -- what you're proposing can totally wrap these built in tracked-built-ins as well as cell -- that could even (and this is my preference) be a separate subsequent RFC -- because there are more reactive utilities to implement beyond just the 6 that this RFC is concerned with.
no, that is out of scope for this RFC. For a deep-do-everything utility, a new RFC could be written that builds on all this that is maybe exported from import { tracked } from '@ember/reactive/all';
// or something short like
// '@ember/x';
// if, during implementation of tracked-built-ins,
// we figure out how to more generally implement all these utilities
// without shipping so many bytes |
yes, I'm speaking exactly that. What will we make public and thus define the experience for people. Currently we have this narrative: "Use JS as you are used to. Use I see this parallel to react's Which is why I consider this question important:
Let's put this together with an example and two approaches to deal with it. Example: const customer = reactive({
givenName: 'Luke',
familyName: 'Skywalker',
address: {
planet: 'Tatooine',
location: 'At my uncles farm'
}
});
function moveToHooth(customer) {
customer.address.planet = 'Hooth';
customer.address.location = 'Rebell base';
} ... and somewhere in the template we render the address. This example would work in svelte, because the API was designed to work towards the expectations of consumers. It wouldn't in ember right now as deep reactivity is explicitely excluded, though this is unknown for consumers at first and breaks the narrative of "just use JS". We find ourself somewhere between correctness (given implementation details) and consumer expectation, for which I have two options:
In this case deep reactivity is a given and works with the idea of "performance optimization comes from measuring at first, then apply a treatment" and gives you two functions/parameters:
this idea is a bit with the assumption that most reactive data is ok to be deeply reactive (this is very much subjective by me), but provides an escape hatch for those working on data-heavy apps
Make it explicit in the API what you get:
The learning curve is a bit higher and comes with a couple rounds of frustrations and negative experiences at first. Additional Comments:
Happy to hop on a call to discuss. |
I think you've convinced me to write an RFC for the everything-reactive (even deeply) util -- I am curious what others think tho. Our learning store would then become:
thanks for the detailed write up! |
Based on the discussion from yesterday, I think it was Ed who dropped the idea for the API I'm playing around with. Here are my blurbs: import { reactive } from 'ember/reactive';
// casual usage
const user = reactive({
givenName: 'Luke',
familyName: 'Skywalker',
address: {
planet: 'Tatooine',
location: 'At my uncles farm'
}
});
// advanced usage
const heavySet = reactive.set(new Set()); which comes down to a statement above: "measure your own system and improve upon that" for which explicit/narrowed "sub-functions" exist, that actually carry on this narrative through its syntax. Going into deep nesting, the two options from above persist, but let me precise them. 1) Opt-out: "Just" Use JSdeeply reactive by default.
providing a function as a second parameter gives authors fine control over where they want to make improvements and more importantly how - so they can tailor this to their situation. I dunno how that function would look like and it is rather complex (I guess?), but we can yield supporting utils into that function for people to use, eg. const data = { /* ... */ };
const optimized = reactive(data, (data, key, utils) => {
utils.something();
}); ofc, this would work in "advanced mode" too:
2) Opt-in: Ember optimizes your dataMake it explicit in the API what you get:
for deep reactivity this can come in two forms: a) two functions
b) with param
now, you will receive embers deep reactivity, no control over it though. ThoughtsFrom these two I'd actually consider the opt-out version to have advantages over the opt-in version:
Questions
blurbing end. |
I'm very in favor of deep reactivity being the default (with an escape hatch). I can't think of many times where shallow reactivity would be assumed or wanted (outside of performance reasons). I like the casual/advanced usage @gossi spec'd out:
I would think shallow tracking would be:
I like the idea of passing a function as the second argument for specifying the equality function or other tweaks. |
Propose making tracked-built-ins built-in, which unblocks the implementations of #1000 (array) and #999 (hash)
Rendered
Summary
This pull request is proposing a new RFC.
To succeed, it will need to pass into the Exploring Stage, followed by the Accepted Stage.
A Proposed or Exploring RFC may also move to the Closed Stage if it is withdrawn by the author or if it is rejected by the Ember team. This requires an "FCP to Close" period.
An FCP is required before merging this PR to advance to Accepted.
Upon merging this PR, automation will open a draft PR for this RFC to move to the Ready for Released Stage.
Exploring Stage Description
This stage is entered when the Ember team believes the concept described in the RFC should be pursued, but the RFC may still need some more work, discussion, answers to open questions, and/or a champion before it can move to the next stage.
An RFC is moved into Exploring with consensus of the relevant teams. The relevant team expects to spend time helping to refine the proposal. The RFC remains a PR and will have an
Exploring
label applied.An Exploring RFC that is successfully completed can move to Accepted with an FCP is required as in the existing process. It may also be moved to Closed with an FCP.
Accepted Stage Description
To move into the "accepted stage" the RFC must have complete prose and have successfully passed through an "FCP to Accept" period in which the community has weighed in and consensus has been achieved on the direction. The relevant teams believe that the proposal is well-specified and ready for implementation. The RFC has a champion within one of the relevant teams.
If there are unanswered questions, we have outlined them and expect that they will be answered before Ready for Release.
When the RFC is accepted, the PR will be merged, and automation will open a new PR to move the RFC to the Ready for Release stage. That PR should be used to track implementation progress and gain consensus to move to the next stage.
Checklist to move to Exploring
S-Proposed
is removed from the PR and the labelS-Exploring
is added.Checklist to move to Accepted
Final Comment Period
label has been added to start the FCP