brickjs
v0.3.5
Published
MVVM building block to create real time and large scale applications in a flash
Downloads
3
Maintainers
Readme
Brick
Compose your own MVVM library.
Brick makes it easy to create rich yet maintainable web interfaces by providing a set of composable and extensible components. It uses cement to sync and update your UI with an underlying data store.
Brick has been built for wall, an express-like framework to ease the creation of maintainable and large scale application. Brick is simple, composable and easy to learn.
Give it a try you won't be disappointed!
10 seconds examples
Interpolation (see online):
var view = brick('<span>{{ name }}</span>', {
name: 'bredele'
});
view.build(document.body);
brick('<ul repeat><li>{{ name }}</li></ul>', [{
name: 'bredele'
}])
.use(repeats)
.build();
Factory (see online):
var card = brick.extend('<button>{{ name }}</button>')
.use(interval(100))
var view = card({
name: 'bredele'
}).build();
Browser support
Supporting IE8 is a pain but it's unfortunately still widely used in the industry. This is the reason why brick is fully tested and supports all mainstrean browsers, IE8 included.
IE7 requires the use of JSON and querySelector polyfill.
Concept
Brick is that tiny piece (3kb gzip) that composes well. It follows the UNIX philosophy and provides simply just what you need. Everything else is a module (using npm and browserify or component) with single responsability that you can reuse at scale.
You can compose your owm framework. The possibilities are limitless and commonjs allows you to reuse functionnalities made by the community (npm or component) and stop duplicating your effort.
Event if brick is small, it has a fair bit of power under the hood:
- observer/emitter
- extendable models and collections
- computed properties
- localstorage
- composable views
- fast dom rendering
- interpolation
- filters
- composable data bindings (aka plugins)
- lifecycle hooks (rendered, inserted, ready, removed, etc)
- SVG binding
- IE support
- etc
Brick is also simple. Just a minute is enough to get into it:
<div class="el">
<style>
.brick {
background: {{ color }};
}
</style>
<div class="brick"> {{ label }} </div>
</div>
var view = brick('.el', {
color: 'red',
label: 'Hello'
}).build();
// change label
view.set('label', 'World!');
Let's be honnest, there is enough MV* libraries out there and some of them are actually really good. It's not brick's intent to replace them. Instead, brick's goal is to create an ecosytem of composable components to create rich and maintainable web applications in a flash.
Installation
with component:
$ component install bredele/brick
with nodejs/browserify:
$ npm install brickjs
Documentation
We are currently writing a new documentation but you can find the old one in the wiki.
FAQ
Is it different from other MVVM libraries?
In Brickjs, each view has its own bindings and set of plugins unlike some libraries where everything is contained in a global scope. This is important in order to avoid conflict, memory leaks and to maintain your code properly.
view.add('repeat', require('repeat-brick'));
As shown above, you can give a name to your plugins to avoid name conflicts when different views overlap. Your code is readable and also configurable! You can create your own plugins like jQuery (it's as easy as creating a function) and reuse them multiple times inside or outside of your application.
Why support IE8?
Supporting IE8 is really not complicated and does not make Brickjs slower.
IE8 doesn't support indexOf
and trim
. IE8 has shadow node attributes and doesn't support data
(we use nodeValue
in binding
).
Thats's pretty much it!
What is wall?
Wall has an express-like API and is inspired by this article. It allows you to split your larger application into smaller pieces. Instead having a composite layout where you have a view in a view in a view (and keep references of every views), you have totally independant pieces (with single responsability) that communicate through an event hub.
The main benefits are:
- removing/adding or updating an app doesn't break the others
- easier to test
- easing to maintain
- easier to reuse
- memory safety
You'll see that it'll be easier to get back on your code when your application will become bigger and even a new team member could add, remove or update features in a flash. However. nothing forces you to use it.
Get in Touch
- If you have a related project, plugin or tool, add it to the Wiki page!
- Issues, questions & feature requests: open an issue
- Twitter: @bredeleca
Changelog
See release notes.
License
The MIT License (MIT)
Copyright (c) 2014 Olivier Wietrich [email protected]
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.