Skip to content

Instantly share code, notes, and snippets.

@juanmaguitar
Last active December 15, 2015 08:39
Show Gist options
  • Save juanmaguitar/5233101 to your computer and use it in GitHub Desktop.
Save juanmaguitar/5233101 to your computer and use it in GitHub Desktop.
TinyCore - Quick Start Guide

TinyCore.js

Version 0.4.1

Overview

A tiny modular architecture framework in JavaScript.

Inspiration : "Scalable JavaScript Application Architecture", by Nicholas C. Zakas.

Online demo : A simple todo list application

Features

  • Less than 2.5Kb minified
  • Extensible
  • Supports unit testing of the modules
  • Supports async modules loading using AMD and require.js (less than 1Kb extension)
  • Tested under IE7+, Safari 5.1, Opera 12, Chrome 24+ and Firefox 18+

Benefits

  • Decoupled application architecture
  • Divide & conquer : each module implements only a functionality or a small set of functionalities
  • Modules are independent : change/removal/failure of one does not affect the others
  • Reusability : modules can be reused across a number of different applications
  • Testing : modules can be tested individually both inside and outside of the application

Usage

Include TinyCore.js :

    <script type="text/javascript" src="TinyCore.js"></script> 

This will give you access to the global variable TinyCore and its components : TinyCore.Module, TinyCore.SandBox and TinyCore.ErrorHandler.

##Quick Start Guide

###1.- How to Register and Start a Module

See some examples in action: http://jsfiddle.net/juanma/eQ498/embedded/result/
See the code: http://jsfiddle.net/juanma/eQ498/

####1.1.- Register a Module

Before using a module we need to register it

// Register the Module
TinyCore.Module.register( 'my-module', function( bus ) {
    return {
        onStart: function( oData ) {
            alert(oData.msg);
        }
    };
});

####1.2.- Start a Module

Once the module is registered, we can start it

 TinyCore.Module.start("my-module", { msg : "Hello World!" });

###2.- How to Handle Events

See some examples in action: http://jsfiddle.net/juanma/Sjq4S/embedded/result/
See the code: http://jsfiddle.net/juanma/Sjq4S/

####2.1.- Subscribe to a Topic From one module we can listen to some "event"

// Register the Listener Module    
TinyCore.Module.register( 'module-listener', function( oSandbox ) {
    return {
        onStart: function() {
            oSandbox.subscribe ('my-topic', function(oTopic) {
                alert(oTopic.data.msg);
            });               
        }
    };
});

####2.2.- Publish Topics From another module (or the same is listening this event) we can notify this "topic" (event)

// Register the Notifier Module    
TinyCore.Module.register( 'module-notifier', function( oSandbox ) {
    return {
        onStart: function( oData ) {
            oSandbox.publish ('my-topic', oData );
        }
    };
});

####2.3.- Stoping modules If we want to stop listening to "events" we can stop the module

TinyCore.Module.stop("my-module");

Creators

RoadMap

  • More demos
  • Full API documentation
  • More extensions
  • Add a source map
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment