plugins.html revision d0a16c48f3477794c63f4ff3242dc20db6a49295
0N/A YUI({base:"/build/", filter:"raw", useBrowserConsole:false}).use("basebase", "base-pluginhost", "console", "plugin", "test", function(Y) {
0N/A PluginOne.superclass.constructor.apply(this, arguments);
0N/A PluginOne.NS = "one";
0N/A PluginOne.NAME = "pluginOne";
0N/A PluginOne.ATTRS = {
PluginTwo.superclass.constructor.apply(this, arguments);
PluginTwo.NS = "two";
PluginTwo.NAME = "pluginTwo";
PluginTwo.ATTRS = {
PluginThree.superclass.constructor.apply(this, arguments);
PluginThree.NS = "three";
PluginThree.NAME = "pluginThree";
PluginFour.superclass.constructor.apply(this, arguments);
PluginFour.NS = "four";
PluginFour.NAME = "pluginFour";
PluginFour.ATTRS = {
this.doBefore("methodA", this._methodA, this);
this.doAfter("methodB", this._methodB, this);
this.doBefore("mainAChange", this._onAChange);
this.doAfter("mainBChange", this._afterBChange);
if (e.stack) {
e.stack.push("PluginFour._onAChange");
if (e.stack) {
e.stack.push("PluginFour._afterBChange");
Host.superclass.constructor.apply(this, arguments);
Host.NAME = "host";
Host.ATTRS = {
ExtendedHost.superclass.constructor.apply(this, arguments);
Y.extend(ExtendedHost, Host, {
Y.ObjectAssert.ownsKey("one", h1);
Y.ObjectAssert.ownsKey("two", h1);
Y.ObjectAssert.ownsKey("three", h1);
Y.ObjectAssert.ownsKey("one", h2);
Y.ObjectAssert.ownsKey("two", h2);
h1.plug(PluginOne);
h1.plug(PluginTwo, {two:4});
h1.plug({fn:PluginThree, cfg:{three:6}});
Y.ObjectAssert.ownsKey("one", h1);
Y.ObjectAssert.ownsKey("two", h1);
Y.ObjectAssert.ownsKey("three", h1);
h2.plug([PluginOne, {fn:PluginTwo, cfg:{two:8}}]);
Y.ObjectAssert.ownsKey("one", h2);
Y.ObjectAssert.ownsKey("two", h2);
Y.ObjectAssert.ownsKey("one", h1);
Y.ObjectAssert.ownsKey("two", h1);
h1.unplug("one");
Y.ObjectAssert.ownsKey("two", h1);
h1.unplug(PluginTwo);
Y.ObjectAssert.ownsKey("one", h1);
Y.ObjectAssert.ownsKey("two", h1);
h1.unplug(PluginOne);
h1.plug(PluginOne);
Y.ObjectAssert.ownsKey("one", h1);
h1.plug(PluginOne);
h1.plug(PluginOne);
h1.plug(PluginOne, {a:10});
h1.plug({fn:PluginOne, cfg:{a:10}});
h1.plug([PluginOne, PluginTwo]);
h1.plug([{fn:PluginOne, cfg:{a:10}}, {fn:PluginTwo, cfg:{b:20}}]);
h1.plug([{fn:PluginOne, cfg:{a:10}}, PluginTwo]);
h1.plug(PluginOne, {a:10});
h1.one.on("destroy", function(e) {
actualEvents.push("PluginOne destroy");
h1.plug(PluginOne, {a:20});
h1.unplug(PluginOne);
h1.set("mainA", 10, {stack:stack});
h1.set("mainB", 20, {stack:stack});
Y.ArrayAssert.itemsAreEqual([], stack);
h1.plug(PluginFour);
h1.set("mainA", 11, {stack:stack});
h1.set("mainB", 21, {stack:stack});
Y.ArrayAssert.itemsAreEqual(["PluginFour._onAChange", "PluginFour._afterBChange"], stack);
h1.unplug(PluginFour);
h1.set("mainA", 12, {stack:stack});
h1.set("mainB", 22, {stack:stack});
Y.ArrayAssert.itemsAreEqual([], stack);
h1.methodA(stack);
h1.methodB(stack);
h1.plug(PluginFour);
h1.methodA(stack);
h1.methodB(stack);
Y.ArrayAssert.itemsAreEqual(["PluginFour.methodA", "Host.methodA", "Host.methodB", "PluginFour.methodB"], stack);
h1.unplug(PluginFour);
h1.methodA(stack);
h1.methodB(stack);
Y.Base.plug(Host, PluginOne);
Y.Base.plug(Host, [{fn:PluginTwo, cfg:{}}, PluginThree]);
Y.ObjectAssert.ownsKey("one", h1);
Y.ObjectAssert.ownsKey("two", h1);
Y.ObjectAssert.ownsKey("three", h1);
Y.Base.unplug(Host, PluginThree);
Y.Base.plug(ExtendedHost, PluginThree);
Y.Base.unplug(ExtendedHost, PluginOne);
Y.ObjectAssert.ownsKey("one", h2);
Y.ObjectAssert.ownsKey("two", h2);
Y.ObjectAssert.ownsKey("two", h3);
Y.ObjectAssert.ownsKey("three", h3);
h1.one.after("destroy", function(e) {
destroyed.push("one");
h1.two.after("destroy", function(e) {
destroyed.push("two");
h1.destroy();
Y.ArrayAssert.itemsAreEqual(["one", "two"], destroyed);
new Y.Console({