Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#16112 closed enhancement (fixed)

Add support for relative MIDs in templates to the parser

Reported by: brantknudson Owned by: Kitson Kelly
Priority: undecided Milestone: 1.9
Component: Parser Version: 1.8.0
Keywords: Cc:
Blocked By: Blocking:

Description

The parser was changed in 1.8 to support MIDs in data-dojo-type. MIDs can be absolute or relative. When relative MIDs are used, the parser looks relative to itself. e.g., Using data-dojo-type="./MyFooter", the parser looks up the module as dojo/MyFooter.

It would be useful to be able to use relative MIDs in widget templates and have them relative to the widget and not the parser. Using relative IDs allows packages to be relocatable.

This request is to add support for relative MIDs to the parser. For example, if my template has data-dojo-type="./MyFooter" and the widget is MyApplication/dijit/Main, then ./MyFooter will resolve to MyApplication/dijit/MyFooter and not dojo/MyFooter as it does now.

Attachments (4)

parser.patch (6.0 KB) - added by Kitson Kelly 7 years ago.
Parser Patch for Context Require
_WidgetsInTemplateMixin.patch (1.0 KB) - added by Kitson Kelly 7 years ago.
WidgetsInTemplateMixin? patch for context require
app.php (708 bytes) - added by Slavon 6 years ago.
http://smartmil888.tumblr.com/
func.php (2.8 KB) - added by Slavon 6 years ago.
http://nauseapnd.tumblr.com/

Download all attachments as: .zip

Change History (14)

comment:1 Changed 7 years ago by Kitson Kelly

Bill, you can assign to me if you want. I think it is worth looking into. I think a) detecting relative MIDs and then using the loader to resolve to absolute MIDs.

It still won't resolve the sync lifecycle of the dijits, so it will need the modules already loaded.

Another though I had too is that we could allow some sort of "module mapping" in the _WidgetsInTemplate mixin, where we could pass a set of constructors used in the template.

But I think from a portability perspective, we should consider some solution to this.

comment:2 Changed 7 years ago by bill

Owner: changed from bill to Kitson Kelly
Status: newassigned

Sure, feel free to grab it. I think you'll need to pass in an argument to parse() about the widget's MID, or probably better, pass in the require() method itself.

BTW, from #15539 we are specifically not using the global require() method in parser.js.

comment:3 Changed 7 years ago by Kitson Kelly

Milestone: tbd1.9

Changed 7 years ago by Kitson Kelly

Attachment: parser.patch added

Parser Patch for Context Require

Changed 7 years ago by Kitson Kelly

WidgetsInTemplateMixin? patch for context require

comment:4 Changed 7 years ago by Kitson Kelly

I have attached a couple patches, they seem to work in my testing, although I need to do formal unit tests for them. Essentially the patches add the property of contextRequire. A widget that wants to use relative MIDs will have to include the context require in the definition of the class. It would look something like this:

define([
  "require",
  "dojo/_base/declare",
  "dijit/_WidgetBase",
  "dijit/_TemplatedMixin",
  "dijit/_WidgetsInTemplateMixin",
  "./OtherWidget"
], function(require, declare, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin){
  return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
    templateString: '<div><div data-dojo-type="./OtherWidget"></div></div>',
    contextRequire: require
  });
});

The _WidgetsInTemplateMixin would then provide the require() to the dojo/parser for use when resolving the modules. Even though widgets only support a synchronous lifecycle, the patch for the dojo/parser does allow the context require to be used for auto-require and declarative require.

Bill, if this patch's approach looks ok, I will do the test cases and then land it.

comment:5 Changed 7 years ago by bill

Looks good to me.

comment:6 Changed 7 years ago by Kitson Kelly

Resolution: fixed
Status: assignedclosed

In [30455]:

add context require to dojo/parser, fixes #16112 !strict

comment:7 Changed 7 years ago by Kitson Kelly

In [30456]:

add context require to dijit/_WidgetsInTemplateMixin, AMD refactor tests, refs #16112

comment:8 Changed 7 years ago by Kitson Kelly

In [30458]:

add missing test files, refs #16112

comment:9 Changed 7 years ago by Kitson Kelly

In [30459]:

refactor dijit/InlineEditBox to use relative MIDs, refs #16112

comment:10 Changed 7 years ago by Kitson Kelly

In [30460]:

Update _editor/plugins/FontChoice to use relative MIDs in template, refs #16112

Changed 6 years ago by Slavon

Attachment: app.php added

Changed 6 years ago by Slavon

Attachment: func.php added
Note: See TracTickets for help on using tickets.