GithubHelp home page GithubHelp logo

ducnghiemminh / core-sandbox-module-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mamoo/core-sandbox-module-js

0.0 2.0 0.0 158 KB

A simple implementation of the Core Sandbox Module pattern in Javascript

JavaScript 92.40% HTML 1.61% CSS 6.00%

core-sandbox-module-js's Introduction

Core-Sandbox-Module Pattern Implementation

INDEX

  1. SUMMARY
  2. DESCRIPTION
  3. HOW-TO

SUMMARY

A quite basic implementation of Core-Sandbox-Module pattern. API is based on talks and slides by N. Zakas[1] and Eric Shepherd[2]. This implementation heavily relies upon a correct use of the revealing module pattern [3], and upon the publish/subscribe pattern. Base library (jQuery is used here) is lightly abstracted from sandbox and modules; some main functions are exposed like sandbox.DOM.find(selector) which is equivalent to $().

DESCRIPTION

Aim of the pattern is providing a loosely coupled architecture for JS applications.

Architecture components are:

  1. Base library Provides cross-browser functionalities. JQuery is used here.

  2. Core object Is responsible for:

    • Registering modules
    • Starting modules
    • Stopping modules
    • Indirectly handling (via sandbox) pub/sub of messages
    • Exposing some basic functions of base lib to sandbox
  3. Sandbox Sandbox is responsible for:

    • Providing access to common features to modules
    • Provide a pub/sub API to modules
    • Exposing some basic functions of core's base lib to sandbox
  4. Module(s) Each module is defined by a Module Creator function, knows only about its Sandbox and is subject to these rules:

    • Hands to yourself – Only call your own methods or those on the sandbox – Don't access DOM elements outside of your box
      • Don't access non-native global objects
    • Ask, don't take
      • Anything else you need, ask the sandbox
    • Don't leave your toys around – Don't create global objects
    • Don't talk to strangers – Don't directly reference other modules
      • Don't mess with other module's markup

HOW TO USE IT

Basically is all about:

  1. Defining modules
  2. Registering modules
  3. Starting/stopping modules

MODULE DEFINITION:

 var MyModule = function (sandbox){
     return {
        init: function(){
            //Module initialization
        },
 
        destroy: function(){
            //Module destruction
        }
        
        // put your code here, and use your sandbox as needed...     
    };
}

You can only have one unique name per module.

MODULE REGISTRATION:

Core.register("myModule", MyModule);

APPLICATION START:

Core.startAll();

REFERENCES

[1] Nicholas Zakas' Core-Sandbox-Module

[2] Building a JavaScript Module Framework at Gilt

[3] Christian Heilmann’s Revealing-module pattern

core-sandbox-module-js's People

Contributors

mamoo avatar njhamann avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.