GithubHelp home page GithubHelp logo

duster-ko's Introduction

Duster-Ko

Note on Development

Social Tables is not actively developing Duster-KO at the moment, and as such it may not be up to date with the latest changes to Dust and/or Knockout. Use at your own discretion. We are, however, always open to suggestions and pull requests.

Summary

Duster-KO is a Dust.JS[1] implementation & hack-up of a Knockout[2] Template Engine[3]. There's not a lot of the well famed uber-schmancy asynchronous & parallel Dust.js super-powers going on; this is a pretty straight & simple means of using Dust.js templates.

Table of Contents

  usage
  implementation
  why the dust hack
    the source
  references

Usage

Is pretty straightforwards:

  • include and give an id for each compiled dust template: <script type="application/javascript" src="mytemplate.dust.js" id="mytemplate"/>
  • bind to it. <div data-bind="mytemplate"/>
  • ko.applyBindings(myModelView)
  • ...
  • uh, you also neeed to hack Dust. :( (hack already done & provided)

Implementation

Oh, pretty straightforwards, not much magic.

  • Create a Dust helper-filter and make it default, to evaluate Observerable objects properly (call as a function with no arguments).
  • Derive a utterly vanilla Knockout Template Engine that calls into Dust.
  • A small hack to Dust to keep it from trying to evaluate Observables like functional Dust tags. See: :(

Why the Dust hack

:(

Unpleasant business, that.

Dust expects any functional tags to accept a set of parameters (chunk, context). We could build a Dust-friendly wrapper for every KO Observer, and build Dust contexts out of these, but that seems like an awful lot of unnecessary object creation.

Instead, we just hack Dust to not evaluate Observers like it normally would, and handle the aftermath with a more stock standard helper-filter.

The Source

These changes are done in whatever dust*js you're using.

Prime hackery:

Chunk.prototype.reference = function(elem, context, auto, filters) {
-  if (typeof elem === "function") {
+  if (typeof elem === "function" && elem.name != "observable") {
     elem = elem(this, context, null, {auto: auto, filters: filters});`

Oh, also, we're manually invoking some Dust templates & cough eval'ing that. To manually invoke the template, we need to pass in a Dust Chunk object, which normally we wouldn't be exposed to, so:

+dust.chunk= Chunk

Tis all! Checkout lib/dust-patch.js for a patch against unspecified Dust sources (for now, dust-core-0.3.0.js is the intended target).

References

  1. http://akdubya.github.com/dustjs/
  2. http://knockoutjs.com/
  3. https://github.com/SteveSanderson/knockout/blob/master/src/templating/templateEngine.js

duster-ko's People

Contributors

alonronin avatar danberger avatar rektide avatar soci-viii 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.