Balloons.js is an event-based JavaScript library to build front-end components or widgets.
Benefits:
- Dependency-free.
- Just 983 bytes (min & gzip).
- Uses vanilla JavaScript.
- Made it with love.
### Q.define([parents], members) Defines new components constructors.
parents
(optional): [Array] - An optional collection of constructors to inherit.members
: [Object] - A given members to be attached to component's prototype.
// Defines a Foobar component that inhertis from Foo and Bar constructors.
var Foobar = Q.define([Foo, Bar], {
'name': 'Foobar',
'init': function () {
console.log(this.name);
},
'sayFoobar': function () {
console.log('foobar');
}
});
// Creates a new instance of Foobar component.
var foobar = new Foobar();
Creates a new instance of an Event Emitter or adds observer methods to a given component.
component
(optional): [Function] - A given constructor function.
// Creates a new instance of Emitter.
var emitter = Q.emitter();
// Add observer methods to component Foo.
Q.emitter(Foo);
Adds a listener
to the collection for a specified event
.
event
: [String] - The name of the event you want to add.listener
: [Function] - Listener you want to add from given event.once
(optional): [Boolean] - Indicates if the given listener should be executed only once.
emitter.on('live', listener);
Adds a one time listener
to the collection for a specified event
. It will execute only once.
event
: [String] - The name of the event.listener
: [Function] - Listener you want to add from the given event.
emitter.once('live', listener);
Removes a listener
from the collection for a specified event
.
event
: [String] - The name of the event.listener
: [Function] - Listener you want to remove from the given event.
emitter.off('live', listener);
Returns all listeners
from the collection for a specified event
.
event
: [String] - The name of theevent
.
emitter.getListeners('live');
Execute each of the listeners
collection in order with the given parameters.
All emitters emit the event newListener
when new listeners are added.
event
: [String] - The name of the event you want to emit.
emitter.emit('live', 'data1', 'data2');
An object that encapsulates how a set of objects interact. Q.mediator
implements the Mediator Pattern in JavaScript. (Read more).
Q.mediator
has the same methods as an instance of Q.emitter()
.
### Q.clone(obj) Returns a shallow-copied clone of a given object.
obj
: [Object] - A given object to clone.
var foo = {
'baz': 'qux'
};
var bar = Q.clone(foo);
### Q.extend(destination, from) Extends a given object with properties from another object.
destination
: [Object] - A given object to extend its properties.from
: [Object] - A given object to share its properties.
var foo = {
'baz': 'qux'
};
var bar = {
'quux': 'corge'
};
Q.extend(foo, bar);
Inherits prototype properties from uber
into child
constructor.
child
: [Function] - A given constructor function who inherits.uber
: [Function] - A given constructor function to inherit.
function Bar() {
// Some code here
}
function Foo() {
// Some code here
}
Q.inherit(Foo, Bar);
-
Open your terminal and clone
balloonsjs/balloons
by running:$ git clone git@github.com:balloonsjs/balloons.git
-
Now go to the project's folder:
$ cd balloons
-
Install its dependencies:
$ npm install
-
Install
grunt-cli
:$ npm install grunt-cli -g
-
Develop! :)
## Grunt tasks
grunt dev
: Builds a development version.grunt test
: Runs Jasmine tests.grunt dist
: Creates a distrubution version of Balloons. You should find two files:.dist/Q.js
and.dist/Q.min.js
.
## Maintained by
- Guille Paz (@pazguille)
- Her Mammana (@hmammana)
- Lean Linares (@lean8086)
## License Licensed under the MIT license.
Copyright (c) 2014 BalloonsJS.