Code Monkey home page Code Monkey logo

gpc-ko-widgets's Introduction

GPC-KO-Widgets

A Knockout-based collection (in embryo state) of reusable JavaScript widgets

Disclaimer

In its present state, this project is little more than a proof of concept, though it does contain one usable widget (TreeView).

Quick Start

First, obtain the package via npm install gpc-ko-widgets.

GPC-KO-Widgets is built for consumption via browserify. Browserify not only handles module imports, but CSS injection as well by making use of the excellent cssify transform.

First off, your code will of course need knockout, as well as its plugin knockout-mapping:

var ko = require('knockout');
var ko.mappings = require('knockout.mappings');

To be able to use a widget, your code must also import the module implementing its view model:

var TreeView = require('gpc-ko-widgets/treeview');

Instantiating a widget is a matter of using Knockout's template binding, like so:

div(data-bind="template: { name: 'gktvTreeView', data: myTreeview }")

... and providing a TreeView object as part of your Knockout view-model:

var myTree = {
    'Item 1': {},
    'Item 2': {
        'Subitem 2.1': {},
        'Subitem 2.2': {},
    },
    'Item 3': {}
};

var myViewModel = { 
    myTreeview: new gpc.kowidgets.TreeView( ko.mapping.fromJS(myTree) ),
};

/* Called from body.onload (or as part of jQuery "ready" function) */
window.start = function() {
    ko.applyBindings(myViewModel);
}

And that's it! Thanks to Browserify and friends, you don't have to worry about copying CSS files and referencing them from your HTML.

More to come

There is quite a bit more to say about this project, but I'm out time at the moment. Stay tuned for an explanation of how GPC-KO-Widgets leverages both Jade and Knockout templates, and how it uses actual data models on top of Knockout's usual view models.

gpc-ko-widgets's People

Contributors

jpgygax68 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.