Skip to content

Commit

Permalink
refactored set/getObject, mixin, exists from dojo/_base/kernel to doj…
Browse files Browse the repository at this point in the history
…o/_base/lang; further loader and kernel cleanup and minifying; refs #13484; !strict

git-svn-id: http://svn.dojotoolkit.org/src/dojo/trunk@25850 560b804f-0ae3-0310-86f3-f6aa0a117693
  • Loading branch information
rcgill committed Jul 20, 2011
1 parent e47d31d commit b31aae3
Show file tree
Hide file tree
Showing 38 changed files with 1,162 additions and 1,203 deletions.
2 changes: 1 addition & 1 deletion NodeList-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ define([
}else{
// must be a setter, mix `value` into data hash
// API discrepency: using object as setter works here
r = dojo._mixin(dataCache[pid], key);
r = lang.mixin(dataCache[pid], key);
}

return r; // Object|Anything|Nothing
Expand Down
2 changes: 1 addition & 1 deletion NodeList-fx.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ lang.extend(NodeList, {
var a = dfx.combine(
this.map(function(item){
var tmpArgs = { node: item };
dojo.mixin(tmpArgs, args);
lang.mixin(tmpArgs, args);
return obj[method](tmpArgs);
})
);
Expand Down
4 changes: 2 additions & 2 deletions Stateful.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define(["./_base/kernel", "./_base/declare", "./_base/array"], function(dojo, declare) {
define(["./_base/kernel", "./_base/declare", "./_base/lang", "./_base/array"], function(dojo, declare, lang) {
// module:
// dojo/Stateful
// summary:
Expand All @@ -16,7 +16,7 @@ return dojo.declare("dojo.Stateful", null, {
// | obj.set("foo","bar");
postscript: function(mixin){
if(mixin){
dojo.mixin(this, mixin);
lang.mixin(this, mixin);
}
},

Expand Down
8 changes: 4 additions & 4 deletions _base/Color.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define(["./kernel", "./array", "./lang"], function(dojo){
define(["./kernel", "./lang", "./array"], function(dojo, lang){

dojo.Color = function(/*Array|String|Object*/ color){
// summary:
Expand All @@ -22,10 +22,10 @@ define(["./kernel", "./array", "./lang"], function(dojo){
if(color){ this.setColor(color); }
};

/*=====
dojo.mixin(dojo.Color,{
/*=====
lang.mixin(dojo.Color,{
named:{
// summary: Dictionary list of all CSS named colors, by name. Values are 3-item arrays with corresponding RG and B values.
// summary: Dictionary list of all CSS named colors, by name. Values are 3-item arrays with corresponding RG and B values.
}
});
=====*/
Expand Down
10 changes: 5 additions & 5 deletions _base/NodeList.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define(["./kernel", "../on", "./lang", "./array", "./html"], function(dojo, on){
define(["./kernel", "./lang", "../on", "./lang", "./array", "./html"], function(dojo, lang, on){
// module:
// dojo/_base/NodeList
// summary:
Expand All @@ -25,7 +25,7 @@ define(["./kernel", "../on", "./lang", "./array", "./html"], function(dojo, on){
}
var ctor = NodeListCtor || this._NodeListCtor || dojo._NodeListCtor;
a.constructor = ctor;
dojo._mixin(a, ctor.prototype);
lang.mixin(a, ctor.prototype);
a._NodeListCtor = ctor;
return parent ? a._stash(parent) : a;
};
Expand Down Expand Up @@ -244,7 +244,7 @@ define(["./kernel", "../on", "./lang", "./array", "./html"], function(dojo, on){
nlp.connect = adaptAsForEach(function(){
return dojo.connect.apply(this, arguments);
});

dojo.extend(dojo.NodeList, {
_normalize: function(/*String||Element||Object||NodeList*/content, /*DOMNode?*/refNode){
// summary:
Expand Down Expand Up @@ -378,7 +378,7 @@ define(["./kernel", "../on", "./lang", "./array", "./html"], function(dojo, on){
// summary:
// Listen for events on the nodes in the NodeList. Basic usage is:
// | query(".my-class").on("click", listener);
// This supports event delegation by using selectors as the first argument with the event names as
// This supports event delegation by using selectors as the first argument with the event names as
// pseudo selectors. For example:
// | dojo.query("#my-list").on("li:click", listener);
// This will listen for click events within <li> elements that are inside the #my-list element.
Expand Down Expand Up @@ -935,7 +935,7 @@ define(["./kernel", "../on", "./lang", "./array", "./html"], function(dojo, on){
// example:
// Grabs all buttons in the page and converts them to diji.form.Buttons.
// | var buttons = dojo.query("button").instantiate("dijit.form.Button", {showLabel: true});
var c = dojo.isFunction(declaredClass) ? declaredClass : dojo.getObject(declaredClass);
var c = dojo.isFunction(declaredClass) ? declaredClass : lang.getObject(declaredClass);
properties = properties || {};
return this.forEach(function(node){
new c(properties, node);
Expand Down
4 changes: 2 additions & 2 deletions _base/array.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define(["./kernel", "./lang"], function(dojo){
define(["./kernel", "./lang"], function(dojo, lang){
// module:
// dojo/_base/array
// summary:
Expand All @@ -25,7 +25,7 @@ define(["./kernel", "./lang"], function(dojo){
return every; // Boolean
};

dojo.mixin(dojo, {
lang.mixin(dojo, {
indexOf: function( /*Array*/ array,
/*Object*/ value,
/*Integer?*/ fromIndex,
Expand Down
2 changes: 0 additions & 2 deletions _base/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,3 @@ define([
// This module causes the browser-only base modules to be loaded.
return dojo;
});


78 changes: 52 additions & 26 deletions _base/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,61 @@ define(["../has", "require"], function(has, require){
// module:
// dojo/_base/config
// summary:
// This module processes the user configuration during bootstrap.
// This module defines the user configuration during bootstrap.
// description:
// By defining user configuration as a module value, an entire configuration can be specified in a build,
// thereby eliminating the need for sniffing and or explicitly setting in the global variable dojoConfig.
// Also, when multiple instances of dojo exist in a single application, each will necessarily be located
// at an unique absolute module identifier as given by the package configuration. Implementing configuration
// as a module allows for specifying unique, per-instance configurations.
// example:
// Create a second instance of dojo with a different, instance-uniqe configuration (assume the loader and
// dojo.js are already loaded).
// | // specify a configuration that creates a new instance of dojo at the absolute module identifier "myDojo"
// | require({
// | packages:[{
// | name:"myDojo",
// | location:".", //assume baseUrl points to dojo.js
// | }]
// | });
// |
// | // specify a configuration for the myDojo instance
// | define("myDojo/config", {
// | // normal configuration variables go here, e.g.,
// | locale:"fr-ca"
// | });
// |
// | // load and use the new instance of dojo
// | require(["myDojo"], function(dojo) {
// | // dojo is the new instance of dojo
// | // use as required
// | });

has.add("dojo-sniff",
// inspect script elements for data-dojo-config during bootstrap
has("dom") ? 1 : 0
);

var result = this.dojoConfig || this.djConfig || {};
if(has("dom") && has("dojo-sniff") && !has("dojo-loader")){
// if we're not under the dojo loader, then assume the user doesn't want to sniff the baseUrl from the loader (since it must already be set)
// notice this loop breaks on first match
for(var config, src, match, scripts = document.getElementsByTagName("script"), i = 0; i < scripts.length && !match; i++){
if((src = scripts[i].getAttribute("src")) && (match = src.match(/(.*)\/?(dojo|require)\.js(\W|$)/i))){
// see if there's a dojo configuration stuffed into the node
config = (scripts[i].getAttribute("data-dojo-config") || scripts[i].getAttribute("djConfig"));
if(config){
config = eval("({ " + config + " })\r\n//@ sourceURL=dojo/config/data-dojo-config");
for(var p in config){
result[p] = config[p];
}
}
var adviseHas = function(featureSet, prefix, booting){
for(p in featureSet){
has.add(prefix + p, featureSet[p], 0, booting);
}
},
result;
if(has("dojo-config-api")){
// must be the dojo loader; take a shallow copy of require.rawConfig
var src = require.rawConfig, dest = {}, p;
for(p in src){
dest[p] = src[p];
}
result = dest;
require.on("config", function(config){
adviseHas(config, "config", 0);
adviseHas(config.has, "", 0);
});
}else{
// if this is the dojo loader, then the aggregate of defaultConfig + (dojoConfig | djConfig | require) + sniffed config will be in require.rawConfig
var p, rawConfig = require.rawConfig || {};
for(p in rawConfig){
result[p] = rawConfig[p];
}
result = has("dojo-loader") ?
// must be a built version of the dojo loader; all config stuffed in require.rawConfig
require.rawConfig :
// a foreign loader
this.dojoConfig || this.djConfig || {};
adviseHas(result, "config", 1);
adviseHas(result.has, "", 1);
}
return result;
});
Expand All @@ -43,7 +69,7 @@ define(["../has", "require"], function(has, require){
// Setting any of these variables *after* the library has loaded does
// nothing at all.
// FIXME: can we document these on dojo.config object and explain they must be set via djConfig/dojoConfig global prior to loading dojo.js
// FIXME: can we document these on dojo.config object and explain they must be set via djConfig/dojoConfig global prior to loading dojo.js
dojoConfig = {
// summary:
Expand Down
43 changes: 22 additions & 21 deletions _base/configNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ exports.config = function(config){
"dojo-inject-api":1,
"dojo-timeout-api":0,
"dojo-trace-api":1,
"dojo-loader-catches":1,
"dojo-dom-ready-api":0,
"dojo-publish-privates":1,
"dojo-sniff":0,
Expand All @@ -54,29 +53,31 @@ exports.config = function(config){
// TODO: really get the locale
locale:"en-us",

debug: function(item){
// define debug for console messages during dev instead of console.log
// (node's heavy async makes console.log confusing sometimes)
require("util").debug(item);
},
loaderPatch: {
log:function(item){
// define debug for console messages during dev instead of console.log
// (node's heavy async makes console.log confusing sometimes)
require("util").debug(item);
},

eval: function(__text, __urlHint){
return vm.runInThisContext(__text, __urlHint);
},
eval: function(__text, __urlHint){
return vm.runInThisContext(__text, __urlHint);
},

injectUrl: function(url, callback){
try{
vm.runInThisContext(fs.readFileSync(url, "utf8"), url);
callback();
}catch(e){
console.log("failed to load resource (" + url + ")");
console.log(e);
}
},
injectUrl: function(url, callback){
try{
vm.runInThisContext(fs.readFileSync(url, "utf8"), url);
callback();
}catch(e){
this.require.log("failed to load resource (" + url + ")");
this.require.log(e);
}
},

getText: function(url, sync, onLoad){
// TODO: implement async and http/https handling
onLoad(fs.readFileSync(url, "utf8"));
getText: function(url, sync, onLoad){
// TODO: implement async and http/https handling
onLoad(fs.readFileSync(url, "utf8"));
}
}
};
for(p in nodeConfig){
Expand Down
34 changes: 18 additions & 16 deletions _base/configRhino.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,24 +93,26 @@ function rhinoDojoConfig(config, baseUrl, rhinoArgs){
timeout:0,
locale:String(java.util.Locale.getDefault().toString().replace('_', '-').toLowerCase()),

injectUrl: function(url, callback){
try{
if(isLocal(url)){
load(url);
}else{
require.eval(readUrl(url, "UTF-8"));
loaderPatch:{
injectUrl: function(url, callback){
try{
if(isLocal(url)){
load(url);
}else{
require.eval(readUrl(url, "UTF-8"));
}
callback();
}catch(e){
console.log("failed to load resource (" + url + ")");
console.log(e);
}
callback();
}catch(e){
console.log("failed to load resource (" + url + ")");
console.log(e);
}
},
},

getText: function(url, sync, onLoad){
// TODO: test https://bugzilla.mozilla.org/show_bug.cgi?id=471005; see v1.6 hostenv_rhino
// note: async mode not supported in rhino
onLoad(isLocal(url) ? readFile(url, "UTF-8") : readUrl(url, "UTF-8"));
getText: function(url, sync, onLoad){
// TODO: test https://bugzilla.mozilla.org/show_bug.cgi?id=471005; see v1.6 hostenv_rhino
// note: async mode not supported in rhino
onLoad(isLocal(url) ? readFile(url, "UTF-8") : readUrl(url, "UTF-8"));
}
}
};
for(p in rhinoConfig){
Expand Down
22 changes: 11 additions & 11 deletions _base/connect.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define(["./kernel", "../on", "../aspect", "./event", "../mouse", "../has", "./lang", "../keys"], function(dojo, on, aspect, eventModule, mouse, has){
define(["./kernel", "../on", "../aspect", "./event", "../mouse", "../has", "./lang", "../keys"], function(dojo, on, aspect, eventModule, mouse, has, lang){
// module:
// dojo/_base/connect
// summary:
Expand All @@ -23,7 +23,7 @@ function connect(obj, event, context, method, dontFix){
event = event.substring(2);
}else if(!obj || !(obj.addEventListener || obj.attachEvent)){
// it is a not a DOM node and we are using the dojo.connect style of treating a
// method like an event, must go right to aspect
// method like an event, must go right to aspect
return aspect.after(obj || dojo.global, event, dojo.hitch(context, method), true);
}
if(!obj){
Expand Down Expand Up @@ -66,7 +66,7 @@ var evtCopyKey = dojo.isMac ? "metaKey" : "ctrlKey";


var _synthesizeEvent = function(evt, props){
var faux = dojo.mixin({}, evt, props);
var faux = lang.mixin({}, evt, props);
setKeyChar(faux);
// FIXME: would prefer to use dojo.hitch: dojo.hitch(evt, evt.preventDefault);
// but it throws an error when preventDefault is invoked on Safari
Expand Down Expand Up @@ -152,7 +152,7 @@ if(has("events-keypress-typed")){
});
};
}else{
keypress = function(object, listener){
keypress = function(object, listener){
return on(object, "keypress", function(evt){
setKeyChar(evt);
return listener.call(this, evt);
Expand Down Expand Up @@ -263,7 +263,7 @@ return {
// with the same scope (this):
// | dojo.connect(null, "globalEvent", null, globalHandler);
// | dojo.connect("globalEvent", globalHandler); // same

// normalize arguments
var a=arguments, args=[], i=0;
// if a[0] is a String, obj was omitted
Expand All @@ -275,8 +275,8 @@ return {
for(var l=a.length; i<l; i++){ args.push(a[i]); }
return connect.apply(this, args);
},


disconnect: dojo.disconnect = dojo.unsubscribe = function(/*Handle*/ handle){
// summary:
// Remove a link created by dojo.connect.
Expand All @@ -288,7 +288,7 @@ return {
handle.remove();
}
},

// topic publish/subscribe
subscribe: dojo.subscribe = function(/*String*/ topic, /*Object|null*/ context, /*String|Function*/ method){
// summary:
Expand All @@ -303,10 +303,10 @@ return {
// example:
// | dojo.subscribe("alerts", null, function(caption, message){ alert(caption + "\n" + message); });
// | dojo.publish("alerts", [ "read this", "hello world" ]);

// support for 2 argument invocation (omitting context) depends on hitch
return on(topic, dojo.hitch(context, method));
},
},
/*=====
dojo.unsubscribe = function(handle){
// summary:
Expand Down Expand Up @@ -334,7 +334,7 @@ dojo.unsubscribe = function(handle){
// example:
// | dojo.subscribe("alerts", null, function(caption, message){ alert(caption + "\n" + message); };
// | dojo.publish("alerts", [ "read this", "hello world" ]);

// Note that args is an array, which is more efficient vs variable length
// argument list. Ideally, var args would be implemented via Array
// throughout the APIs.
Expand Down
Loading

0 comments on commit b31aae3

Please sign in to comment.