Aah…can do that? That came to my mind but wasn’t sure because that “level” is going to be an object in the list. Thanks!
The other reason I didn’t give it much thought or did not try it was because I wanted to set another flag “hasChanged” in that “level” object. This is because, it can be a big list and I don’t want to send across the whole list back. Using the “hasChanged” flag I can just filter the list and send the filtered list back to server.
How can I achieve it if I go your route?
Unless we’re talking at least tens of thousands of items, I think worrying about this is premature optimization.
That being said, if you insist, you could use something like lodash’s clone() method to prepare a “before” version of levelDetails, and then compare it to the “after” version modified by user actions at submission time to see which levels have changed.
I think so, especially if the list is big. The way you had it, you had to walk the entire list on every toggle flip. With clone-and-compare, that only has to happen once, after all toggles have been modified.
So the above functionality is on of the pages in my app. On the click of “Done” button (as in point #3 in my original post), instead of submitting/sending the list to server I want to go back to the previous page which I can do using “pop()” method, however, I don’t know how to carry this changed list back to the previous page.
@rapropos - that is a great solution! Thanks a lot!
How dumb of me not to come up with something similar. Maybe because I was thinking there has to be some cleaner and Ionic specific way. This is not to say your way is not cleaner, it’s just more work, so to say.
Apparently, after reading through forums and tutorial websites and documentation, Ionic doesn’t have a pop() method, like push(), in which we can pass objects/values. And nothing in the plans too, it looks like.
From a best practices perspective, what do you think of this solution?
Not a huge fan. I’m skeptical of explicit Promise construction in general, and I think that idea creates overly tight coupling between pages. Say a third page gets involved. It has to be initiated into the web of communication. When you let service providers do all the data handling, adding additional consumers (pages) is trivial and does not introduce any additional code complexity that must be tested and can introduce subtle bugs.