Skip to content

Commit

Permalink
_WidgetBase: remove deprecated code, refs #4
Browse files Browse the repository at this point in the history
- attributeMap
- connect()/disconnect(), subscribe()/publish()
- uninitialize()
- this._connects & this._supportingWidgets
- stop reading id from DOMNode; that's the parser's job

Still need to make destroy() work recursively.
  • Loading branch information
wkeese committed May 10, 2013
1 parent ad93d4e commit f5035f9
Showing 1 changed file with 23 additions and 185 deletions.
208 changes: 23 additions & 185 deletions _WidgetBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ define([
"dojo/_base/array", // array.forEach array.map
"dojo/aspect",
"dojo/_base/config", // config.blankGif
"dojo/_base/connect", // connect.connect
"dojo/_base/declare", // declare
"dojo/dom", // dom.byId
"dojo/dom-attr", // domAttr.set domAttr.remove
Expand All @@ -15,35 +14,22 @@ define([
"dojo/_base/kernel",
"dojo/_base/lang", // mixin(), isArray(), etc.
"dojo/on",
"dojo/ready",
"dojo/Stateful", // Stateful
"dojo/topic",
"dojo/_base/window", // win.body()
"./Destroyable",
"dojo/has!dojo-bidi?./_BidiMixin",
"./registry" // registry.getUniqueId(), registry.findWidgets()
], function(require, array, aspect, config, connect, declare,
], function(require, array, aspect, config, declare,
dom, domAttr, domClass, domConstruct, domGeometry, domStyle, has, kernel,
lang, on, ready, Stateful, topic, win, Destroyable, _BidiMixin, registry){
lang, on, Stateful, win, Destroyable, _BidiMixin, registry){

// module:
// dijit/_WidgetBase

// Flag to make dijit load modules the app didn't explicitly request, for backwards compatibility
has.add("dijit-legacy-requires", !kernel.isAsync);

// Flag to enable support for textdir attribute
has.add("dojo-bidi", false);


// For back-compat, remove in 2.0.
if(has("dijit-legacy-requires")){
ready(0, function(){
var requires = ["dijit/_base/manager"];
require(requires); // use indirection so modules not rolled into a build
});
}

// Nested hash listing attributes for each tag, all strings in lowercase.
// ex: {"div": {"style": true, "tabindex" true}, "form": { ...
var tagAttrs = {};
Expand Down Expand Up @@ -217,58 +203,13 @@ define([
_started: false,
=====*/

// attributeMap: [protected] Object
// Deprecated. Instead of attributeMap, widget should have a _setXXXAttr attribute
// for each XXX attribute to be mapped to the DOM.
//
// attributeMap sets up a "binding" between attributes (aka properties)
// of the widget and the widget's DOM.
// Changes to widget attributes listed in attributeMap will be
// reflected into the DOM.
//
// For example, calling set('title', 'hello')
// on a TitlePane will automatically cause the TitlePane's DOM to update
// with the new title.
//
// attributeMap is a hash where the key is an attribute of the widget,
// and the value reflects a binding to a:
//
// - DOM node attribute
// | focus: {node: "focusNode", type: "attribute"}
// Maps this.focus to this.focusNode.focus
//
// - DOM node innerHTML
// | title: { node: "titleNode", type: "innerHTML" }
// Maps this.title to this.titleNode.innerHTML
//
// - DOM node innerText
// | title: { node: "titleNode", type: "innerText" }
// Maps this.title to this.titleNode.innerText
//
// - DOM node CSS class
// | myClass: { node: "domNode", type: "class" }
// Maps this.myClass to this.domNode.className
//
// If the value is an array, then each element in the array matches one of the
// formats of the above list.
//
// There are also some shorthands for backwards compatibility:
//
// - string --> { node: string, type: "attribute" }, for example:
//
// | "focusNode" ---> { node: "focusNode", type: "attribute" }
//
// - "" --> { node: "domNode", type: "attribute" }
attributeMap: {},

// _blankGif: [protected] String
// Path to a blank 1x1 image.
// Used by `<img>` nodes in templates that really get their image via CSS background-image.
_blankGif: config.blankGif || require.toUrl("dojo/resources/blank.gif"),

//////////// INITIALIZATION METHODS ///////////////////////////////////////

/*=====
constructor: function(params, srcNodeRef){
// summary:
// Create the widget.
Expand All @@ -282,8 +223,16 @@ define([
// - use srcNodeRef.innerHTML as my contents
// - if this is a behavioral widget then apply behavior to that srcNodeRef
// - otherwise, replace srcNodeRef with my generated DOM tree

// extract parameters like onMouseMove that should be converted to on() calls
this._toConnect = {};
for(var name in params){
if(!(name in this) && /^on[A-Z]/.test(name)){
this._toConnect[name.substring(2).toLowerCase()] = params[name];
delete params[name];
}
}
},
=====*/

_introspect: function(){
// summary:
Expand All @@ -298,11 +247,6 @@ define([
attrs = ctor._setterAttrs = [], // attributes with custom setters
onMap = (ctor._onMap = {});

// Items in this.attributeMap are like custom setters. For back-compat, remove for 2.0.
for(var name in proto.attributeMap){
attrs.push(name);
}

// Loop over widget properties, collecting properties with custom setters and filling in ctor._onMap.
for(name in proto){
if(/^on/.test(name)){
Expand All @@ -311,9 +255,7 @@ define([

if(/^_set[A-Z](.*)Attr$/.test(name)){
name = name.charAt(4).toLowerCase() + name.substr(5, name.length - 9);
if(!proto.attributeMap || !(name in proto.attributeMap)){
attrs.push(name);
}
attrs.push(name);
}
}

Expand Down Expand Up @@ -363,15 +305,6 @@ define([
// store pointer to original DOM tree
this.srcNodeRef = dom.byId(srcNodeRef);

// No longer used, remove for 2.0.
this._connects = [];
this._supportingWidgets = [];

// this is here for back-compat, remove in 2.0 (but check NodeList-instantiate.html test)
if(this.srcNodeRef && (typeof this.srcNodeRef.id == "string")){
this.id = this.srcNodeRef.id;
}

// mix in our passed parameters
if(params){
this.params = params;
Expand Down Expand Up @@ -400,8 +333,7 @@ define([
var deleteSrcNodeRef;

if(this.domNode){
// Copy attributes listed in attributeMap into the [newly created] DOM for the widget.
// Also calls custom setters for all attributes with custom setters.
// Call custom setters for all attributes with custom setters.
this._applyAttributes();

// If srcNodeRef was specified, then swap out original srcNode for this widget's DOM tree.
Expand Down Expand Up @@ -432,15 +364,12 @@ define([
_applyAttributes: function(){
// summary:
// Step during widget creation to copy widget attributes to the
// DOM according to attributeMap and _setXXXAttr objects, and also to call
// DOM according to _setXXXAttr objects, and also to call
// custom _setXXXAttr() methods.
//
// Skips over blank/false attribute values, unless they were explicitly specified
// as parameters to the widget, since those are the default anyway,
// and setting tabIndex="" is different than not setting tabIndex at all.
//
// For backwards-compatibility reasons attributeMap overrides _setXXXAttr when
// _setXXXAttr is a hash/string/array, but _setXXXAttr as a functions override attributeMap.
// tags:
// private

Expand Down Expand Up @@ -519,6 +448,12 @@ define([
// node dimensions or placement.
// tags:
// protected

// perform connection from this.domNode to user specified handlers (ex: onMouseMove)
for(var name in this._toConnect){
this.on(name, this._toConnect[name]);
}
delete this._toConnect;
},

startup: function(){
Expand Down Expand Up @@ -579,7 +514,6 @@ define([
// Note: This will not yet work with _TemplatedMixin widgets

this._beingDestroyed = true;
this.uninitialize();

function destroy(w){
if(w.destroyRecursive){
Expand All @@ -589,10 +523,6 @@ define([
}
}

// Back-compat, remove for 2.0
array.forEach(this._connects, lang.hitch(this, "disconnect"));
array.forEach(this._supportingWidgets, destroy);

// Destroy supporting widgets, but not child widgets under this.containerNode (for 2.0, destroy child widgets
// here too). if() statement is to guard against exception if destroy() called multiple times (see #15815).
if(this.domNode){
Expand Down Expand Up @@ -653,25 +583,13 @@ define([
});
},

uninitialize: function(){
// summary:
// Deprecated. Override destroy() instead to implement custom widget tear-down
// behavior.
// tags:
// protected
return false;
},

////////////////// GET/SET, CUSTOM SETTERS, ETC. ///////////////////

_setStyleAttr: function(/*String||Object*/ value){
// summary:
// Sets the style attribute of the widget according to value,
// which is either a hash like {height: "5px", width: "3px"}
// or a plain string
// description:
// Determines which node to set the style on based on style setting
// in attributeMap.
// tags:
// protected

Expand All @@ -697,7 +615,6 @@ define([
// summary:
// Reflect a widget attribute (title, tabIndex, duration etc.) to
// the widget DOM, as specified by commands parameter.
// If commands isn't specified then it's looked up from attributeMap.
// Note some attributes like "type"
// cannot be processed this way as they are not mutable.
// attr:
Expand All @@ -706,8 +623,6 @@ define([
// tags:
// private

commands = arguments.length >= 3 ? commands : this.attributeMap[attr];

array.forEach(lang.isArray(commands) ? commands : [commands], function(command){

// Get target node and what we are doing to that node
Expand Down Expand Up @@ -809,17 +724,15 @@ define([
}else{
// Mapping from widget attribute to DOMNode/subwidget attribute/value/etc.
// Map according to:
// 1. attributeMap setting, if one exists (TODO: attributeMap deprecated, remove in 2.0)
// 2. _setFooAttr: {...} type attribute in the widget (if one exists)
// 3. apply to focusNode or domNode if standard attribute name, excluding funcs like onClick.
// 1. _setFooAttr: {...} type attribute in the widget (if one exists)
// 2. apply to focusNode or domNode if standard attribute name, excluding funcs like onClick.
// Checks if an attribute is a "standard attribute" by whether the DOMNode JS object has a similar
// attribute name (ex: accept-charset attribute matches jsObject.acceptCharset).
// Note also that Tree.focusNode() is a function not a DOMNode, so test for that.
var defaultNode = this.focusNode && !lang.isFunction(this.focusNode) ? "focusNode" : "domNode",
tag = this[defaultNode] && this[defaultNode].tagName,
attrsForTag = tag && (tagAttrs[tag] || (tagAttrs[tag] = getAttrs(this[defaultNode]))),
map = name in this.attributeMap ? this.attributeMap[name] :
names.s in this ? this[names.s] :
map = names.s in this ? this[names.s] :
((attrsForTag && names.l in attrsForTag && typeof value != "function") ||
/^aria-|^data-|^role$/.test(name)) ? defaultNode : null;
if(map != null){
Expand Down Expand Up @@ -993,81 +906,6 @@ define([
return registry.getEnclosingWidget(this.domNode.parentNode);
},

connect: function(/*Object|null*/ obj, /*String|Function*/ event, /*String|Function*/ method){
// summary:
// Deprecated, will be removed in 2.0, use this.own(on(...)) or this.own(aspect.after(...)) instead.
//
// Connects specified obj/event to specified method of this object
// and registers for disconnect() on widget destroy.
//
// Provide widget-specific analog to dojo.connect, except with the
// implicit use of this widget as the target object.
// Events connected with `this.connect` are disconnected upon
// destruction.
// returns:
// A handle that can be passed to `disconnect` in order to disconnect before
// the widget is destroyed.
// example:
// | var btn = new Button();
// | // when foo.bar() is called, call the listener we're going to
// | // provide in the scope of btn
// | btn.connect(foo, "bar", function(){
// | console.debug(this.toString());
// | });
// tags:
// protected

return this.own(connect.connect(obj, event, this, method))[0]; // handle
},

disconnect: function(handle){
// summary:
// Deprecated, will be removed in 2.0, use handle.remove() instead.
//
// Disconnects handle created by `connect`.
// tags:
// protected

handle.remove();
},

subscribe: function(t, method){
// summary:
// Deprecated, will be removed in 2.0, use this.own(topic.subscribe()) instead.
//
// Subscribes to the specified topic and calls the specified method
// of this object and registers for unsubscribe() on widget destroy.
//
// Provide widget-specific analog to dojo.subscribe, except with the
// implicit use of this widget as the target object.
// t: String
// The topic
// method: Function
// The callback
// example:
// | var btn = new Button();
// | // when /my/topic is published, this button changes its label to
// | // be the parameter of the topic.
// | btn.subscribe("/my/topic", function(v){
// | this.set("label", v);
// | });
// tags:
// protected
return this.own(topic.subscribe(t, lang.hitch(this, method)))[0]; // handle
},

unsubscribe: function(/*Object*/ handle){
// summary:
// Deprecated, will be removed in 2.0, use handle.remove() instead.
//
// Unsubscribes handle created by this.subscribe.
// Also removes handle from this widget's list of subscriptions
// tags:
// protected

handle.remove();
},

isLeftToRight: function(){
// summary:
// Return this widget's explicit or implicit orientation (true for LTR, false for RTL)
Expand Down

0 comments on commit f5035f9

Please sign in to comment.