jQuery Watcher
Write Mustache.js templates in elements and have them update automatically with reactive data.
Clicked: {{ count }}
Getting Started
Install as a module
npm:
npm i jquery-watcher
yarn:
yarn add jquery-watcher
Initialize the plugin once in your project:
// src/plugins.js // or
CDN
<!-- jQuery --><!-- Mustache.js --><!-- jQuery Watcher -->
API
.watcher(data: Object) => jQuery
Pass a data object that you want to be reactive. Returns jQuery.
This will immediately render your template.
Hello {{ value }}
All of your nested objects will also be reactive.
{{ nested.bird }}
Arrays too!
{{ #starks }} {{.}} {{ /starks }}
.watcher() => Object
If no argument is passed, it will return the reactive data object.
If you manipulate the properties on the reactive object, it will automatically re-render your template.
Hello {{ text }}
.watcher() => [Object, ...]
If there is more than one element, it will return an array of reactive data objects.
{{ hero }}{{ hero }}
Actions
.watcher('set_template', template: String) => jQuery
Sets a new template on the element. Second argument is your string template. Returns jQuery.
This will immediately render your new template if there's data.
{{ things.0 }}
.watcher('render') => jQuery
Renders your template. Useful if you set your template via .html()
. Returns jQuery.
TODOs
- CDN
- Reactive arrays
- Allow template modification
- Config options