Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4829

Oddity with adjusting object query param values in multiple component instances

$
0
0

@revanar wrote:

I ran into a strange issue the other day while trying to create a component that could remove keys from a queryParam Object---When the components computed the new query param, they also had an effect on the existing query param, and on each other.

Here is a twitter that demonstrates:

https://ember-twiddle.com/06327b4b9158a4986560f8193da37aae?openFiles=components.delete-key.js%2Ctemplates.components.delete-key.hbs&route=%2F%3Fobj%3D%257B%2522first%2522%253A%255B%2522a%2522%252C%2522b%2522%252C%2522c%2522%255D%252C%2522second%2522%253A%255B%2522d%2522%252C%2522e%2522%255D%257D

Clicking the first button loads an object into the "obj" queryParam. When you click the second button, it loads an instance of the "delete-key" component for each key in "obj". Since all the component contains is a computed value equals the current param with the given key removed from it, I would expect "First" to contain "Second", and "Second" to contain "First"---in other words, for each call of the delete-key component to display everything but its own key/values. However, as you can see, the key that the first call of the delete-key component deletes persists over to the second key, resulting in no values being displayed, despite the fact that both instances of the component ought to be displaying a computed properties, and not modifying the original value passed to them.

In my Ember.js project, I also found by putting console.log(params) into my application route's model(params) hook, that each time a component loaded, it was removing its key from the queryParam itself---but I have no idea why this would be happening, and I was unsuccessful in reproducing it in my twiddle.

Does anyone have a good explanation for why this is behaving the way it is, rather than the way I expected it to? Am I misunderstanding something about how components ought to work, or is this some sort of bug with queryParams? Any insight would be appreciated!

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4829

Trending Articles