-
Notifications
You must be signed in to change notification settings - Fork 8
Create a brick
- Create a brick
- Options and methods * html * build * data * add
- Interpolation * computed properties * advances expressions * filters * partials
- Data-binding
A brick
is basically a piece of Ui that the user will see on his screen. Its API is really straightforward and is as simple as the example below:
var brick = require('brick');
var view = brick();
See the full list of options and methods
A brick
basically render a DOM element from its data and keep them both in sync. When the data changes the DOM element update itself and vice versa.
var view = brick('<div class="github {{repo}}">{{maple}}</div>', {
repo: 'brick',
github: 'bredele'
});
//compile and insert
view.build(document.body);
view.set('repo','brick-examples');
With brick
you can control the life cycle of your DOM element (through methods and hooks), extend the template engine by creating new filters, directive or partials and add data-bindings to listen events, hide/show, create lists and way more. Really it has never been so easy!
view.html(tmpl)
-
tmpl:
String
orHTMLElement
emit
rendered
event
Render and initialize DOM element.The result is available under view.el
.
Variable substitution ({{var}}
) and bindings are applied only when inserted into the document (method el
).
view.el([node , bool])
-
node: optional
HTMLElement
anchor (parent element) -
bool: optional
Boolean
emit
compiled
event
Compile (apply bindings and interpolation) and place DOM element into parent element. If the second argument is true, the view will only apply bindings (no interpolation).
view.data(data)
-
data:
Object
orStore
brick
inherits from Store.
view.plug(name, plugin)
-
name:
Object
orString
-
plugin:
Function
orObject
Extend the HTML syntax of your view by creating new attributes (aka brick/data-binding).
//listen clik and execute handler
<button on-click="handler> my button </button>
Every plugins are executed in the compilation time.
Like jQuery you can create your own plugins : it's as easy as creating a function. See plugin for more information.
Using data binding allows a better separation of concerns. You code is more configurable and so, more maintainable. Moreover, you don't need to use query selection anymore.
Variable interpolation is a simple way to set the content of a DOM node with a data variable. Your HTML stays up-to-date when the underlying data changes.
<ul>
<li class="{{repo}}">
<a href="http://github.com/{{name}}">{{name}}</a>
</li>
</ul>
With brick
, you can use every attributes and content of a DOM/SVG node. Moreover, you can do way more than just basic interpolation!
brick
makes interpolation even better and allows you to create computed properties and advanced expression without writing any JavaScript!
<a href="http://github/{{name + '/' + repo}}">visitor{{ visitor!==1 ? 's' : '' }}</a>
Brick caches every expression for better performance.
todo
todo
todo