A state is something that is affected by you and the memory of that. This something can be you clicking on an element, like a button, or you typing some text into an element. The state resides in your browser’s RAM. It deals with JavaScript objects like arrays, strings, objects, and so on.
In this article we’re going to dig into a pattern of taking these arrays and objects and persist them. To do that, we’ll need some clever ways in JavaScript to separate the temporary “junk” for the really important stuff we can’t lose.
Getting Started
Let’s say that we have an array of objects and each object has “temporary” keys in it. We don’t want these keys to be persistent when sending the array of objects in for a persistent store (localStorage
or Ajax).
In the example I’m going to show you, we’ll work with an AngularJS app. In it, we put things into each object that don’t need to be persistent. Everything that is not important to be persistent starts with an underscore.
Continue reading %What’s in a State and How to Persist It%
by Peter Bengtsson via SitePoint
No comments:
Post a Comment