Giter Site home page Giter Site logo

dojo-typescript-class's Introduction

dojo-typescript-class

This is an experiment aimed at using TypeScript to create Dojo classes. There have been several attempts by different people already. This attempt aims at making the creation of Dojo classes from TypeScript as comfortable as possible with the minimum of weird code duplication and pitfalls.

The magic is in dojoClass.js and for examples of usage see MyTSDojoBaseClass.ts and MyTSDojoSubclass.ts. The idea is to create classes using the normal TypeScript/ES6 syntax, then to pass that prototype object to Dojo's declare() function to create the Dojo class, and then merge the interesting bits in the Dojo class back into the TypeScript one.

Running the unit tests

There are a couple of steps needed to run the tests for this code.

Improvements and more tests are welcome.

-- cheers,

Simon Edwards

[email protected] https://github.com/sedwards2009

dojo-typescript-class's People

Contributors

sedwards2009 avatar

Watchers

 avatar  avatar

Forkers

msgpo

dojo-typescript-class's Issues

Almost completely awesome! but...

Hello,

I have been playing around with this technique and agree that it is, in most ways, superior to the one that I had come up with. Only one problem that I see: for templated widgets, I can't find an order that instantiates the widget correctly.

The canonical way to try this would be something like:

///<amd-dependency path="dojo/text!./_templates/template.html" />
/// <reference path="../../typings/dijit.d.ts" />

import dojoClass = require("app/dojoClass");
import _WidgetBase = require("dijit/_WidgetBase");
import _TemplatedMixin = require("dijit/_TemplatedMixin");

var template: string = require("dojo/text!./_templates/RulesView.html");

class Foo extends dijit._WidgetBase {
    templateString: string = template;

    constructor(params?: Object, elem?: HTMLElement) {
        super();
        dojoClass.construct(this, params, elem);
    }
}

dojoClass.create(Foo, [_WidgetBase, _TemplatedMixin]);

export=Foo;

however, this causes the application to try to new up the super (dijit._WidgetBase) and the new widget. This causes Dojo to throw an error since it tries to double instantiate this widget and assign them both the same ID.

If we can find a way around this, then I think it addresses all of the use cases in a much more efficient way. I'll keep working on it and update this issue if I find anything.

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.