For some reordering code I call splice on an array of Breeze entities. Generally this works fine, but on removing an entity using splice from the array, its navigation properties are set to null. After adding the same entity back into the same array on a different position, navigation property seems to be restored, but the entityState has already changed to modified.
The responsible code seems to be this call.
Is there a way to move an entity in an array of entities to a different position without having the entityState to be changed?
As responded by in a GitHub issue: Workaround is to use a temporary standard array instead of an observable array, process the arrays using splice in the temporary array and write them back to the observable array.
Related
I have an array of Objects (ES6 Class I created). When I delete this objects from within the array I store them, it seems like it isnt fully "destroyed". These Object classes have websocket connections to external APIs and even when I remove these Objects from my Object Array using splice (which works) I still see the websocket events coming in for them.
How can I really destroy the whole Instance of the object when I remove it from my array?
When using redux and you try to store a map into it, you get an error:
A non-serializable value was detected in the state
Why is that? I know the doc says you can't but it doesn't explain why. Because you can't directly JSON.stringify a map? But you can do something like this...
m = new Map()
m.set("1", "2")
JSON.stringify([...m]);
A map can under specific cirumstances be serializable and de-serializable if you provide the logic by that by hand, using map.entries() and Map.fromEntries(...).
Assuming that all keys and values of the map are themselves serializable - which is not necessarily the case, since maps can take any object as a key (and value, of course).
It cannot be serialized automatically by calling JSON.serialize in a way that would allow you to reconstruct it by calling JSON.parse - and that is what most tools rely on.
So, using a Map could break middleware like redux-persist (unless you add more logic there) and countless others and sometimes even (depending on what you put in here and what you use as keys) even go so far as to crash your DevTools.
Since a map that only contains serializable values & keys has no real benefits over just using a normal object for the same purpose, we recommend just using plain JavaScript objects instead of maps.
I've been having difficulty understanding how Knockout Observable Arrays work, more specifically replacing certain vales within them. I keep thinking I've got it right until further down the line when something else doesn't work correctly.
Due to the complexity of my viewmodel (Observable Arrays of Observable Arrays of Observables with subscriptions to update their respective arrays) I won't post the full extent of my actual issue, especially as there is clearly a fundamental misunderstanding here.
I've essentially got it narrowed down to 2 possibilities, examples below, where; groups = KO Array of observable objects/arrays and rightTargetPropertyName = KO array of obs strings
filter().groups()[0].rightTargetPropertyName([ko.observable("placeholder")])[0];
The above works but I feel like it will replace the whole array with a single value as the UI grows
filter().groups()[0].rightTargetPropertyName()[0]("placeholder");
This one above seems like it should be the correct way to change a single observable value in an observable array but the subscriptions/computed values aren't triggered when this code is run.
So in summary, which is the correct way to modify observable values in observable arrays? If the second method is correct (as I suspect) I can debug further.
Thanks in advance
The question title says it all. Here are a couple related pages from the Firebase docs:
writing data
managing lists
Is there a better way to update all the items in an "array" on Firebase?
Note that using .push on a ref in firebase does not append to an array but rather an array-like object with non-ordinal keys that look like -JH1w9H0qPJIFu_OF_JO. If you want to work with actual JavaScript arrays, you need to treat them as a unit. That is, any time you update a property that contains an array you have to set the entire array -- you can't use Firebase to update individual components of the array.
If you need ordered data, use priorities.
That being said, it is safe to write arrays ([]) as properties in Firebase. If you have a list and you need to update each property of the list, you cycle through the snapshot (once you've retrieved it from the ref using .value or the like) using .forEach. You can then us .update on each individual child.
Briefly, if I set LazyLoadingEnabled=true when setting data context in my server code, I am getting strange JSON objects, objects with their only property being $ref instead of real JSON objects when I calling the arrays from javascript via AJAX.
Otherwise (with LazyLoadingEnabled=false), all elements are correctly returned. But problem with LazyLoadingEnabled=false is that I can't use navigation properties at all in my server code. because I will get an runtime error saying one of navigation properties null.
So my question: Is there any way returning array with correct elements with LazyLoadingEnabled=true?
You need to get your lazy loaded navigation properties before serialization.