Two-way data-binding is sooo 2009.
Nothing fancy here. Just include Tripod.js on your page.
Ideally, it should be included just before the closing body
tag in your document.
If not, it's cool. Tripod can deal.
var tripod = new Tripod();
tripod.set('who', 'world');
or
var tripod = new Tripod({ who: 'world' });
tripod.push('who');
push()
manually pushes your data to all bound DOM nodes.set()
performs apush()
for you.
<body>
...
<p>Hello, <span data-bound-to="who"></span>!</p>
...
</body>
To save the data to LocalStorage and automatically sync across tabs, we need to make two small changes to our Javascript:
var tripod = new Tripod({ who: 'world' }, '', true);
tripod.sync('who');
First, we have to pass true
as the third argument to our constructor. This tells Tripod to sync changes to LocalStorage.
Second, we use sync()
rather than push()
to move our data around.
sync()
first calls load()
to grab data from LocalStorage.
In this basic example, we passed an empty string ''
as the namespace, which means no namespace.
In your code, you'll want to include a namespace
when storing data in LocalStorage to help prevent collisions.