0.0.20 • Published 9 years ago

dynamic-models v0.0.20

Weekly downloads
56
License
-
Repository
github
Last release
9 years ago

Dynamic Models Build Status

Requirejs plugin for managing communication between Workers and browser

Why "Dynamic Models"

Dynamic Models simplify messaging between Browser and web workers. There is support for shared workers, and fallback to web workers, if shared workers not supported.

Prerequisites

You need to install nodejs and grunt CLI globally npm -g install grunt-cli

Also need Requirejs knowledge.

Installation

Using npm

npm install dynamic-models

Using Bower

bower install dynamic-models

Usage

To use it need add path in require.config.

For node_modules

paths:{
    ...
    'dm': '../node_modules/dynamic-models/dist/prod/dm'
    ...
}

For bower_components

paths:{
    ...
    'dm': '../bower_components/dynamic-models/dist/prod/dm'
    ...
}

Defining a model

Just Extend Model Class

define(['dm/Model'], function (Model) {
    return Model.extend({
        init: function () {
            this.data = {
                a: 0,
                b: 2
            }
            this.eventBus.publish('getData', this.data);
            this.eventBus.subscribe('setData', function(data) {
                this.data = data
            }, this);
            
            this.localEventBus.subscribe('setModelData', function (data) {
                this.data = data;
            },{},this);
        }
    });
});

In a Model, you have access to eventBus, which are proxy between messaging. You can subscribe and publish messages. Init is a constructor. in a Models also available localEventBus wich allow to communicate between models.

Use Models in Browser

Requirejs plugin will return model eventBus.

define([
    'dm!./PathToModel'
    ], function(model){
        model.eventBus.subscribe('getData', function (data) {
            console.log(data);
        });
        
        model.eventBus.publish('getData', {
            a:5,
            b:10
        });
    });
    

Messaging, allows only Objects, not functions. (because concept of Workers).

0.0.20

9 years ago

0.0.19

9 years ago

0.0.18

9 years ago

0.0.17

9 years ago

0.0.16

9 years ago

0.0.15

9 years ago

0.0.14

9 years ago

0.0.13

9 years ago

0.0.12

9 years ago

0.0.11

9 years ago

0.0.10

9 years ago

0.0.9

9 years ago

0.0.8

9 years ago

0.0.7

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago