Ticket #3183: dojox.wire_20070529.patch
| File dojox.wire_20070529.patch, 15.4 kB (added by jaredj, 19 months ago) |
|---|
-
wire.js
1 dojo.provide("dojox.wire"); 2 dojo.require("dojox.wire._base"); 3 -
wire/Wire.js
Property changes on: wire.js ___________________________________________________________________ Name: svn:eol-style + native
1 1 dojo.provide("dojox.wire.Wire"); 2 2 3 dojo.require("dojox.wire. common");3 dojo.require("dojox.wire._base"); 4 4 5 5 dojo.declare("dojox.wire.Wire", 6 6 null, -
wire/tests/wire.js
1 1 dojo.provide("dojox.wire.tests.wire"); 2 2 3 3 try{ 4 dojo.require("dojox.wire.tests.programmatic. common");4 dojo.require("dojox.wire.tests.programmatic._base"); 5 5 dojo.require("dojox.wire.tests.programmatic.Wire"); 6 6 dojo.require("dojox.wire.tests.programmatic.DataWire"); 7 7 dojo.require("dojox.wire.tests.programmatic.XmlWire"); -
wire/tests/programmatic/common.js
1 dojo.provide("dojox.wire.tests.programmatic.common");2 3 dojo.require("dojox.wire.common");4 5 tests.register("dojox.wire.tests.programmatic.common", [6 7 function test_create(t){8 var wire = dojox.wire.create({});9 t.assertTrue(wire instanceof dojox.wire.Wire);10 11 wire = dojox.wire.create({property: "a"});12 t.assertTrue(wire instanceof dojox.wire.Wire);13 14 wire = dojox.wire.create({attribute: "a"});15 t.assertTrue(wire instanceof dojox.wire.DataWire);16 17 wire = dojox.wire.create({path: "a"});18 t.assertTrue(wire instanceof dojox.wire.XmlWire);19 20 wire = dojox.wire.create({children: "a"});21 t.assertTrue(wire instanceof dojox.wire.CompositeWire);22 23 wire = dojox.wire.create({columns: "a"});24 t.assertTrue(wire instanceof dojox.wire.TableAdapter);25 26 wire = dojox.wire.create({nodes: "a"});27 t.assertTrue(wire instanceof dojox.wire.TreeAdapter);28 29 wire = dojox.wire.create({segments: "a"});30 t.assertTrue(wire instanceof dojox.wire.TextAdapter);31 32 wire = dojox.wire.create({wireClass: "dojox.wire.DataWire"});33 t.assertTrue(wire instanceof dojox.wire.DataWire);34 },35 36 function test_transfer(t){37 var source = {a: "A"};38 var target = {};39 dojox.wire.transfer(40 {object: source, property: "a"},41 {object: target, property: "a"});42 t.assertEqual(source.a, target.a);43 },44 45 function test_connect(t){46 var trigger = {transfer: function() {}, transferArgument: function() {}};47 var source = {a: "A"};48 var target = {};49 dojox.wire.connect({scope: trigger, event: "transfer"},50 {object: source, property: "a"},51 {object: target, property: "a"});52 trigger.transfer();53 t.assertEqual(source.a, target.a);54 55 // with argument56 target = {};57 dojox.wire.connect({scope: trigger, event: "transferArgument"},58 {property: "[0].a"},59 {object: target, property: "a"});60 trigger.transferArgument(source);61 t.assertEqual(source.a, target.a);62 63 // by topic64 target = {};65 dojox.wire.connect({topic: "transfer"},66 {object: source, property: "a"},67 {object: target, property: "a"});68 dojo.publish("transfer");69 t.assertEqual(source.a, target.a);70 71 // by topic with argument72 target = {};73 dojox.wire.connect({topic: "transferArgument"},74 {property: "[0].a"},75 {object: target, property: "a"});76 dojo.publish("transferArgument", [source]);77 t.assertEqual(source.a, target.a);78 },79 80 function test_disconnect(t){81 var trigger = {transferDisconnect: function() {}};82 var source = {a: "A"};83 var target = {};84 var connection = dojox.wire.connect({scope: trigger, event: "transferDisconnect"},85 {object: source, property: "a"},86 {object: target, property: "a"});87 trigger.transferDisconnect();88 t.assertEqual(source.a, target.a);89 delete target.a;90 dojox.wire.disconnect(connection);91 trigger.transferDisconnect();92 t.assertEqual(undefined, target.a);93 94 // by topic95 target = {};96 connection = dojox.wire.connect({topic: "transferDisconnect"},97 {object: source, property: "a"},98 {object: target, property: "a"});99 dojo.publish("transferDisconnect");100 t.assertEqual(source.a, target.a);101 delete target.a;102 dojox.wire.disconnect(connection);103 dojo.publish("transferDisconnect");104 t.assertEqual(undefined, target.a);105 }106 107 ]); -
wire/tests/programmatic/_base.js
1 dojo.provide("dojox.wire.tests.programmatic. common");1 dojo.provide("dojox.wire.tests.programmatic._base"); 2 2 3 dojo.require("dojox.wire. common");3 dojo.require("dojox.wire._base"); 4 4 5 tests.register("dojox.wire.tests.programmatic. common", [5 tests.register("dojox.wire.tests.programmatic._base", [ 6 6 7 7 function test_create(t){ 8 8 var wire = dojox.wire.create({}); -
wire/common.js
1 dojo.provide("dojox.wire.common");2 3 dojox.wire._defaultWireClass = "dojox.wire.Wire";4 5 dojox.wire._wireClasses = {6 "attribute": "dojox.wire.DataWire",7 "path": "dojox.wire.XmlWire",8 "children": "dojox.wire.CompositeWire",9 "columns": "dojox.wire.TableAdapter",10 "nodes": "dojox.wire.TreeAdapter",11 "segments": "dojox.wire.TextAdapter"12 };13 14 dojox.wire.register = function(/*Function||String*/wireClass, /*String*/key){15 // summary:16 // Register a Wire class17 // desription:18 // The specified Wire class or a class name is registered with19 // a key property of arguments to create a Wire20 // wireClass:21 // A class or full qualified class name22 // key:23 // A key property of arguments to create a Wire24 if(!wireClass || !key){25 return; //undefined26 }27 if(dojox.wire._wireClasses[key]){ // key already in use28 return; //undefined29 }30 dojox.wire._wireClasses[key] = wireClass;31 };32 33 dojox.wire._getClass = function(/*String*/name){34 // summary:35 // Returns a class36 // description:37 // The class is loaded by dojo.require() and returned38 // by dojo.getObject().39 // name:40 // A class name41 // returns:42 // A class43 dojo["require"](name); // use dojo["require"] instead of dojo.require to avoid a build problem44 return dojo.getObject(name); //Function45 };46 47 dojox.wire.create = function(/*Object*/args){48 // summary:49 // Create a Wire from arguments50 // description:51 // If 'args' specifies 'wireClass', it is used as a class or full52 // qualified class name to create a Wire with 'args' as arguments.53 // Otherwise, a Wire class is determined by other proeprties of 'args'54 // checking if 'args' specifies a key property for a Wire class.55 // If no key property found, the default Wire class is used.56 // args:57 // Arguments to create a Wire58 // returns:59 // A Wire60 if(!args){61 args = {};62 }63 var wireClass = args.wireClass;64 if(wireClass){65 if(dojo.isString(wireClass)){66 wireClass = dojox.wire._getClass(wireClass);67 }68 }else{69 for(var key in args){70 if(!args[key]){71 continue;72 }73 wireClass = dojox.wire._wireClasses[key];74 if(wireClass){75 if(dojo.isString(wireClass)){76 wireClass = dojox.wire._getClass(wireClass);77 dojox.wire._wireClasses[key] = wireClass;78 }79 break;80 }81 }82 }83 if(!wireClass){84 if(dojo.isString(dojox.wire._defaultWireClass)){85 dojox.wire._defaultWireClass = dojox.wire._getClass(dojox.wire._defaultWireClass);86 }87 wireClass = dojox.wire._defaultWireClass;88 }89 return new wireClass(args); //Object90 };91 92 dojox.wire.isWire = function(/*Object*/wire){93 // summary:94 // Check if an object is a Wire95 // description:96 // If the specified object is a Wire, true is returned.97 // Otherwise, false is returned.98 // wire:99 // An object to check100 // returns:101 // True if the object is a Wire, otherwise false102 return (wire && wire._wireClass); //Boolean103 };104 105 dojox.wire.transfer = function(/*Wire||Object*/source, /*Wire||Object*/target, /*Object?*/defaultObject, /*Object?*/defaultTargetObject){106 // summary:107 // Transfer a source value to a target value108 // description:109 // If 'source' and/or 'target' are not Wires, Wires are created with110 // them as arguments.111 // A value is got through the source Wire and set through the target112 // Wire.113 // 'defaultObject' is passed to Wires as a default root object.114 // If 'defaultTargetObject' is specified, it is passed to the target115 // Wire as a default root object, instead of 'defaultObject'.116 // source:117 // A Wire or arguments to create a Wire for a source value118 // target:119 // A Wire or arguments to create a Wire for a target value120 // defaultObject:121 // defaultTargetObject;122 // Optional default root objects passed to Wires123 if(!source || !target){124 return; //undefined125 }126 if(!dojox.wire.isWire(source)){127 source = dojox.wire.create(source);128 }129 if(!dojox.wire.isWire(target)){130 target = dojox.wire.create(target);131 }132 133 var value = source.getValue(defaultObject);134 target.setValue(value, (defaultTargetObject || defaultObject));135 };136 137 dojox.wire.connect = function(/*Object*/trigger, /*Wire||Object*/source, /*Wire||Object*/target){138 // summary:139 // Transfer a source value to a target value on a trigger event or140 // topic141 // description:142 // If 'trigger' specifies 'topic', the topic is subscribed to transer143 // a value on the topic.144 // Otherwise, the event specified to 'event' of 'trigger' is listened145 // to transfer a value.146 // On the specified event or topic, transfer() is called with147 // 'source', 'target' and the arguments of the event or topic (as148 // default root objects).149 // trigger:150 // An event or topic to trigger a transfer151 // source:152 // A Wire or arguments to create a Wire for a source value153 // target:154 // A Wire or arguments to create a Wire for a target value155 // returns:156 // A connection handle for disconnect()157 if(!trigger || !source || !target){158 return; //undefined159 }160 161 var connection = {topic: trigger.topic};162 if(trigger.topic){163 connection.handle = dojo.subscribe(trigger.topic, function(){164 dojox.wire.transfer(source, target, arguments);165 });166 }else if(trigger.event){167 connection.handle = dojo.connect(trigger.scope, trigger.event, function(){168 dojox.wire.transfer(source, target, arguments);169 });170 }171 return connection; //Object172 };173 174 dojox.wire.disconnect = function(/*Object*/connection){175 // summary:176 // Remove a connection or subscription for transfer177 // description:178 // If 'handle' has 'topic', the topic is unsubscribed.179 // Otherwise, the listener to an event is removed.180 // connection:181 // A connection handle returned by connect()182 if(!connection || !connection.handle){183 return; //undefined184 }185 186 if(connection.topic){187 dojo.unsubscribe(connection.topic, connection.handle);188 }else{189 dojo.disconnect(connection.handle);190 }191 }; -
wire/CompositeWire.js
1 1 dojo.provide("dojox.wire.CompositeWire"); 2 2 3 dojo.require("dojox.wire. common");3 dojo.require("dojox.wire._base"); 4 4 dojo.require("dojox.wire.Wire"); 5 5 6 6 dojo.declare("dojox.wire.CompositeWire", -
wire/_base.js
1 dojo.provide("dojox.wire. common");1 dojo.provide("dojox.wire._base"); 2 2 3 3 dojox.wire._defaultWireClass = "dojox.wire.Wire"; 4 4 -
wire/ml/Transfer.js
6 6 7 7 dojo.require("dijit.base.Widget"); 8 8 dojo.require("dijit.base.Container"); 9 dojo.require("dojox.wire. common");9 dojo.require("dojox.wire._base"); 10 10 dojo.require("dojox.wire.ml.Action"); 11 11 12 12 dojo.declare("dojox.wire.ml.Transfer", -
wire/ml/DataStore.js
1 1 dojo.provide("dojox.wire.ml.DataStore"); 2 2 3 3 dojo.require("dijit.base.Widget"); 4 dojo.require("dojox.wire. common");4 dojo.require("dojox.wire._base"); 5 5 6 6 dojo.declare("dojox.wire.ml.DataStore", 7 7 dijit.base.Widget, { -
wire/ml/Service.js
5 5 6 6 dojo.require("dijit.base.Widget"); 7 7 dojo.require("dojox.data.dom"); 8 dojo.require("dojox.wire. common");8 dojo.require("dojox.wire._base"); 9 9 dojo.require("dojox.wire.ml.util"); 10 10 11 11 dojo.declare("dojox.wire.ml.Service", -
wire/README
1 2 joX Wire 3 ------------------------------------------------------------------------------- 4 Version 0.9 5 Release date: 05/29/2007 6 ------------------------------------------------------------------------------- 7 Project state: beta 8 ------------------------------------------------------------------------------- 9 Project authors 10 Jared Jurkiewicz (jared.jurkiewicz@gmail.com) 11 ------------------------------------------------------------------------------- 12 Project description 13 14 The DojoX Wire project is a set of functions that build a generic data binding 15 and service invocation library to simplify how data values across a wide 16 variety of widget and non-widget JavaScript constructs are accessed, updated, 17 and passed to and from services. It also provides a set of widgets 18 within the dojox.wire.ml package to allow for declarative data binding 19 definitions in addition to the programmatic APIs. 20 21 In essense, this project is an API to provide a simplified way of doing MVC 22 patterns in the client. 23 24 ------------------------------------------------------------------------------- 25 Dependencies: 26 27 DojoX Wire has dependencies on core dojo, the dijit widget system (for classes 28 in the dojox.wire.ml package), dojox.data, and the D.O.H. unit test framework. 29 ------------------------------------------------------------------------------- 30 Documentation: 31 32 See the Dojo API tool (http://dojotoolkit.org/api) 33 ------------------------------------------------------------------------------- 34 Installation instructions 35 36 Grab the following from the Dojo SVN Repository: 37 http://svn.dojotoolkit.org/var/src/dojo/dojox/trunk/wire.js 38 http://svn.dojotoolkit.org/var/src/dojo/dojox/trunk/wire/* 39 40 Install into the following directory structure: 41 /dojox/wire/ 42 43 ...which should be at the same level as your Dojo checkout. 44 45 It should look like: 46 /dojox/wire.js 47 /dojox/wire/* 48 49 Require in dojox.wire for all baseline functions (dojox.wire.connect, 50 dojox.wire.register, etc). For specific Wire classes, 51 require in the appropriate dojox.wire.<Class>. 52 ------------------------------------------------------------------------------- 53