Skip to content

About

A light, backbone-like type of observer module

Resources

Stars

0 stars

Watchers

2 watching

Forks

Latest commit

 

History

7 Commits

Folders and files

Repository files navigation

Observer-lite

A light, backbone-like type of observer module built on ES2015.

This Observer (pub/sub) module contains basic functionality you can find in popular frameworks such as backbone.js.

Features: Features Model and View classes.
Dependencies: None.
Note: Transpile to ES5 for cross-browser compatibility.

The Model

Contains data and trigger events when the data changes (unless passed the parameter silent:true). Everytime data changes two events are triggered, a generic “change” event and a name-spaced “change:event” event.

Methods:

.set():
Add or modify data in model object. This will trigger events for all subscribed views.
Syntax 1: model.set( property, value, silent);

Syntax 2: model.set({ Property: value, Property: value }, null, silent);
Note: Silent is an optional parameter that when set to true won’t fire any event.

.get():
Get value from model.
Syntax: model.set( property);

.trigger():
Forces an event trigger on model.
Syntax: model.trigger(event);

.on():
Attaches a name-spaced event to a method.
Syntax: model.on(‘change:value’, this.method);

.off():
Removes event from lists of events on model.
Syntax: model.off(‘change:value’);

The View:

Views subscribe to the models through the built-in .on() method, and they can listen for changes happening on the model’s data so they can react automatically.

Methods:

Initialize():
If method initialize is declared, it will run automatically when the instance is created.

$():
Just like jQuery (and how backbone implemented it) the method this.$() is a handy shorthand for document.querySelectorAll(selector).

About

A light, backbone-like type of observer module

Resources

Stars

0 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages