103 lines
2.8 KiB
HTML
103 lines
2.8 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
|
|
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
|
|
|
<title>Test Dijit Subscribe</title>
|
|
|
|
<script type="text/javascript" src="../../dojo/dojo.js" data-dojo-config="isDebug: true"></script>
|
|
<script type="text/javascript">
|
|
dojo.require("doh.runner");
|
|
dojo.require("dijit._Widget");
|
|
dojo.require("dojo.parser");
|
|
|
|
dojo.ready(function(){
|
|
var numCallsInternal = 0;
|
|
var numCallsExternal = 0;
|
|
var externalString = "";
|
|
var internalSubscribe = null;
|
|
|
|
dojo.declare("dijit.MyWidget", dijit._Widget, {
|
|
_subscribeHandlerInternal: function(){ numCallsInternal++; }
|
|
});
|
|
|
|
doh.register("parse", function(){
|
|
dojo.parser.parse();
|
|
});
|
|
|
|
doh.register("_widgetSubscribe",
|
|
[
|
|
{
|
|
name: "_Widget.subscribe - set up subscriptions",
|
|
runTest: function(t){
|
|
var w = dijit.byId("widget1");
|
|
internalSubscribe = w.subscribe("/custom/event",
|
|
"_subscribeHandlerInternal");
|
|
w.subscribe("/custom/event", function(){
|
|
if(this == w){
|
|
numCallsExternal++;
|
|
}
|
|
});
|
|
w.subscribe("/custom/setString", function(str){
|
|
if(this == w){
|
|
externalString = str;
|
|
}
|
|
});
|
|
doh.is(0, numCallsInternal);
|
|
doh.is(0, numCallsExternal);
|
|
doh.is("", externalString);
|
|
doh.isNot(null, internalSubscribe);
|
|
}
|
|
},
|
|
{
|
|
name: "_Widget.subscribe - publish events",
|
|
runTest: function(t){
|
|
var w = dijit.byId("widget1");
|
|
dojo.publish("/custom/event", []);
|
|
doh.is(1, numCallsInternal);
|
|
doh.is(1, numCallsExternal);
|
|
dojo.publish("/custom/setString", ["myString"]);
|
|
doh.is("myString", externalString);
|
|
dojo.publish("/custom/setString", ["anotherString"]);
|
|
doh.is("anotherString", externalString);
|
|
}
|
|
},
|
|
{
|
|
name: "_Widget.unsubscribe",
|
|
runTest: function(t){
|
|
var w = dijit.byId("widget1");
|
|
dojo.publish("/custom/event", []);
|
|
doh.is(2, numCallsInternal);
|
|
doh.is(2, numCallsExternal);
|
|
w.unsubscribe(internalSubscribe);
|
|
dojo.publish("/custom/event", []);
|
|
doh.is(2, numCallsInternal);
|
|
doh.is(3, numCallsExternal);
|
|
}
|
|
},
|
|
{
|
|
name: "_Widget.destroy",
|
|
runTest: function(t){
|
|
var w = dijit.byId("widget1");
|
|
w.destroy();
|
|
dojo.publish("/custom/event", []);
|
|
doh.is(2, numCallsInternal);
|
|
doh.is(3, numCallsExternal);
|
|
dojo.publish("/custom/setString", ["myString"]);
|
|
doh.is("anotherString", externalString);
|
|
}
|
|
}
|
|
]
|
|
);
|
|
|
|
doh.run();
|
|
});
|
|
|
|
</script>
|
|
</head>
|
|
<body class="claro">
|
|
<div id="widget1" data-dojo-type="dijit.MyWidget"></div>
|
|
</body>
|
|
</html>
|