GithubHelp home page GithubHelp logo

oceanjack / bundle.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from seich/bundle.js

0.0 2.0 0.0 230 KB

A micro javascript components library.

Home Page: http://code.martianwabbit.com/bundle.js/docs/

License: MIT License

bundle.js's Introduction

Bundle.js

What is this?

Bundle.js is what I call a View-Controller. It is not a full MVC framework, although it might become one eventually. It was built to display data and handle events in the quickest way possible. You can fetch data but that's as far as it's data manipulation skills go at the moment.

Dependencies

Since jQuery is pretty much available everywhere, we depend on it to make bundle.js smaller. We use handlebars to handle templates out of the box (you can change this to something else you might already be using).

Usage

Using Bundle.js is pretty straightforward. You can define a bundle like this:

var Hello = new Bundle({
    // This template will be automatically fetched and compiled.
    template: 'template.hbs',
    
    // This is fetched and the data is merged into the 
    // data object that the template will receive.
    data_src: 'test.json',
    
    // This can be any jQuery method that can be used 
    // to attach html to the DOM such as 'append', 'prepend', 'html'
    render_method: 'html',
    
    // This method is called whenever a new object 
    // is initialized right after it is rendered.
    init: function(el, data) {
        var self = this;
        
        console.log('Hello, the bundle has been drawn.');
    },
    
    // This object contains a set of event bindings.
    events: {
        // All events should be in the form of : '[selector] [event name]'
        'h1 click': function(ev, el) {
            this.say_hi()
        }
    },
    
    // Although you generally shouldn't have to, you can override the render method, 
    // and do whatever you want, in order to render to screen.
    // You receive the element, the data object and the compiled template.
    render: function(el, data, template) {
        el.html(template(data)); // This is pretty much the default render method.
    },
    
    // You can also define your own methods and call them 
    // from any other method in the bundle.
    say_hi: function(todo) {
        console.log('The h1 said "hi"');
    },
    
    // You can define methods that'll be available when a new instance is created using the external
    // setting. This allows you to create a new instance like: new Hello().toggle();
    external: {
        'toggle': function(el) {
            el.find('.dropdown').remove();
        }
    }
});

The bundle constructor generates a new function you can call to initialize the bundle. It takes three parameters:

Hello(element, data, config);

The element, is the element on the document where we want to initialize the bundle. The data and config are both object which can override the data and configuration of the bundle. These are basically merged internally before the render happens.

License

Bundle.js is released under the MIT license.

bundle.js's People

Contributors

seich avatar

Watchers

James Cloos avatar Ocean 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.