How to create Widgets with AMD Dojo/JS
Hy there fellas,
I've wanted to change my old dojo into the new AMD notations but I have a hard struggle on that.
I don't really get the new "define/require" logic from there....
By the way, I am creating RTC Widgets.
But let me Explain first:
1: You need a plugin entry with the name of your widget.
Kinda like. newWidgets.myWidget
2: In the old fashioned way I've just did the provide/declare thing.
dojo.provide("newWidgets.myWidget");
//Requirements
dojo.require("newWidgets.myOtherWidget");
(function() {
//This is the RTC-Wiget superclass to inherit from
var Viewlet = com.ibm.team.dashboard.web.ui.Viewlet;
var MyOtherWidget = newWidgets.myOtherWidget;
//Again the name of myWidget
dojo.declare("newWidgets.myWidget", Viewlet, {
//Under here I can easy instantiate the MyOtherWidget with new
3: with the new AMD Logic I can't require other Classes (Only the Viewlet superclass works)
define([
"dojo/_base/declare",
"dojo/text!myTemplate",
"dojo/domReady!",
], function(declare, template) {
var Viewlet = com.ibm.team.dashboard.web.ui.Viewlet;
return declare(newWidgets.myWidget", Viewlet , {
templateString: template,
4: So my question is, where in this definte thing, can I use "myOtherWidget" or require it to instanstiate?
The Internet told me:
require = use modules
define = define modules
But why can't I use require INSIDE a define?
I've wanted to change my old dojo into the new AMD notations but I have a hard struggle on that.
I don't really get the new "define/require" logic from there....
By the way, I am creating RTC Widgets.
But let me Explain first:
1: You need a plugin entry with the name of your widget.
Kinda like. newWidgets.myWidget
2: In the old fashioned way I've just did the provide/declare thing.
dojo.provide("newWidgets.myWidget");
//Requirements
dojo.require("newWidgets.myOtherWidget");
(function() {
//This is the RTC-Wiget superclass to inherit from
var Viewlet = com.ibm.team.dashboard.web.ui.Viewlet;
var MyOtherWidget = newWidgets.myOtherWidget;
//Again the name of myWidget
dojo.declare("newWidgets.myWidget", Viewlet, {
//Under here I can easy instantiate the MyOtherWidget with new
3: with the new AMD Logic I can't require other Classes (Only the Viewlet superclass works)
define([
"dojo/_base/declare",
"dojo/text!myTemplate",
"dojo/domReady!",
], function(declare, template) {
var Viewlet = com.ibm.team.dashboard.web.ui.Viewlet;
return declare(newWidgets.myWidget", Viewlet , {
templateString: template,
4: So my question is, where in this definte thing, can I use "myOtherWidget" or require it to instanstiate?
The Internet told me:
require = use modules
define = define modules
But why can't I use require INSIDE a define?