Tripod.js

Two-way data-binding is sooo 2009.

Getting and Storing Data in the Instance

The aforementioned getter and setter are creatively named get() and set().

get()

Remember the example firstCar instance we created above? What was the color again? I can't remember.

var theColor = firstCar.get('color');
console.log(theColor); // "Rust"

Note that get() will throw an error if you attempt to access an attribute that doesn't exist.

set()

Oh, darn. We forgot to add the year. No worries.

firstCar.set('year', 1980); // Sweet. This baby is practically brand new.

Note that we can set an attribute that didn't already exist, just like a normal JS object.

You can store many attributes at once by passing a Javascript object to set(). If you really want to micro-optimize, you can pass your object to setMany() to avoid the overhead of the additional function call and type checking.

update()

Sometimes you only want to set an attribute if it already exists in your Tripod instance. update() will do that for you.

The API for update() is identical to set(), so you can update either a single value using update(attributeName, attributeValue) or many values at once using update(object). There's even an updateMany() that is akin to setMany().

When update() is passed an object, it iterates through the object's properties and updates attributes that already exist. Other properties in the object are discarded.

But, wait a minute, my data is in the DOM!

Hang on, we're getting there. I'll give you a hint. You'll want to check out load() and sync() on the next page.