Created
January 16, 2014 21:42
-
-
Save dasa/8463986 to your computer and use it in GitHub Desktop.
Dojo TypeScript extension test. Output js files compiled using: tsc -m amd test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare module "dijit/layout/ContentPane" { | |
class ContentPane { | |
// define methods etc. here | |
} | |
export = ContentPane; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <reference path="./dojo-test"/> | |
var __extends = this.__extends || function (d, b) { | |
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; | |
function __() { this.constructor = d; } | |
__.prototype = b.prototype; | |
d.prototype = new __(); | |
}; | |
define(["require", "exports", "dijit/layout/ContentPane"], function(require, exports, ContentPane) { | |
var LayerStylePane = (function (_super) { | |
__extends(LayerStylePane, _super); | |
function LayerStylePane() { | |
_super.apply(this, arguments); | |
} | |
LayerStylePane.prototype.addSymbol = function (label, symbol) { | |
// impl here | |
}; | |
return LayerStylePane; | |
})(ContentPane); | |
return LayerStylePane; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <reference path="./dojo-test"/> | |
import ContentPane = require("dijit/layout/ContentPane"); | |
export = LayerStylePane; | |
class LayerStylePane extends ContentPane { | |
addSymbol(label: string, symbol: any) { | |
// impl here | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(["require", "exports", "./LayerStylePane"], function(require, exports, LayerStylePane) { | |
var myPane = new LayerStylePane(); | |
myPane.addSymbol("test", {}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import LayerStylePane = require("./LayerStylePane"); | |
var myPane = new LayerStylePane(); | |
myPane.addSymbol("test", {}); |
Regarding the namespace aspect of this question, How would this code extend _Widget? How do you get a reference to it since it's within the "dijit/_Widget" module.
declare module "dijit/layout/ContentPane" {
class ContentPane extends dijit._Widget {
// define methods etc. here
}
export = ContentPane;
}
dojo-test.d.ts
declare module "dijit/_WidgetBase" {
class _WidgetBase {
}
export = _WidgetBase;
}
declare module "dijit/layout/ContentPane" {
import _WidgetBase = require("dijit/_WidgetBase");
class ContentPane extends _WidgetBase {
// define methods etc. here
}
export = ContentPane;
}
To use extends
under 0.9.5, you'd need the style:
declare module "dijit/foo"
{
class foo extends dijit._WidgetBase {}
export = foo;
}
The style I use won't allow it:
declare module "dijit/foo"
{
var foo : typeof dijit._WidgetBase;
export = foo;
}
But there are a lot of places to change.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was able to create a LayerStylePane from via parser.parse as well as dynamically. Not only that, I was able to do this:
var x: typeof LayerStylePane;
var y = new x({}, null);
Why was I under the impression you could not extend a dijit class? How would this work with a templated mixin?