Two-way data-binding is sooo 2009.
The instance is basically just an object that you put data into and pull data out of, just like any other JS object. The main difference here is that you use getters and setters, but we'll get to that in a moment.
Just use the new
keyword and you're on your way. This creates an instance with no set attributes, no namespacing (we'll get to that), and that is not persisted to local storage.
var myAwesomeInstance = new Tripod();
var attributes = {
make: 'Ford',
model: 'Pinto',
color: 'Rust'
};
var namespace = 'vehicle';
var persistToLocalStorage = false;
var firstCar = new Tripod(attributes, namespace, persistToLocalStorage);
So, what did we do?
Hopefully the attributes piece is pretty straightforward. Those are the attributes our object will start with. You can always set more later, this is just to get your object going.
You can add new attributes to your object at any time with set()
.
The namespace tells Tripod which nodes in the DOM belong to this instance. We'll talk about that a little more in minute.
The last argument is a boolean that tells Tripod whether or not to store data in Local Storage as well.
If true
, data is saved in Local Storage as it is updated and changes will synchronize across open browser tabs. Neat!
By default, data is not saved in LocalStorage.