Ticket #6413 (new enhancement)

Opened 8 months ago

Last modified 4 months ago

dojo.data with getters/setters

Reported by: kriszyp Owned by: kzyp
Priority: normal Milestone: 1.3
Component: Data Version: 1.1.0
Severity: normal Keywords: letttable getter setter
Cc: wolfram

Description

Add a wrapping mechanism to dojo.data stores such that items can be directly accessed using normal JS property access and directly modified with normal JS property modification. Getters and setters are used to translate property access to store.getValue calls and property modifications to store.setValue calls. This is based on the define{G|S}etter property in FF and Safari and the lettable hack for IE. I am creating a module dojox.lang.Observable that is a wrapper object that takes a onRead and onRrite listener that are called when read and writes happen. There will also be a dojox.data.JSData that can take a dojo.data store and add this capability. I am open to using different names for these modules...

Attachments

jsdata.diff (16.9 kB) - added by kriszyp 8 months ago.
JSData and observable

Change History

  Changed 8 months ago by wolfram

  • cc wolfram added

Changed 8 months ago by kriszyp

JSData and observable

  Changed 7 months ago by guest

I tested this technique for widget template bindings - please have a look at the forum post.

Eventually I'd like to see this as a part of dijit/dojox, so please let me know what you think of it and how to improve it on that level. CLA Manninen

  Changed 5 months ago by kriszyp

I checked in the dojox.lang.observable module since it is more tested and much more broadly usable. I probably will do some more testing with the JSData (the Dojo Data specific module) before committing it.

  Changed 5 months ago by kzyp

  • milestone changed from 1.2 to 1.3

  Changed 4 months ago by kzyp

  • owner changed from jaredj to kzyp

in reply to: ↑ description ; follow-up: ↓ 8   Changed 4 months ago by kapouer

Hello, perhaps you'll find that line useful ?

document.location = 'vbscript:ExecuteGlobal("Function vb_global_eval(code): ExecuteGlobal(code): End Function")';

that could simplify http://trac.dojotoolkit.org/browser/dojox/trunk/lang/observable.js
line 220 to 243...

i enjoyed very much that trick !

  Changed 4 months ago by kapouer

Also to exchange objects, you have to use "Set" statement :

135	                                               cParts.push(
136	                                                        "       Public Property Let "+prop+"(val)",
137	                                                        "               Call "+setName+"(me.data__,\""+prop+"\",val)",
138	                                                        "       End Property",
139	                                                        "       Public Property Get "+prop,
140	                                                        "               Set "+prop+" = "+getName+"(me.data__,\""+prop+"\")",
141	                                                        "       End Property");

hope this helps...

so that

134	                                        }else if(type != 'object'){ // the getters/setters can only be applied to primitives

could be simply replaced by else {....

in reply to: ↑ 6   Changed 4 months ago by kapouer

Sorry simply adding Set works for objects... but don't work for primitive types...
so i guess some type check must be added.

Note: See TracTickets for help on using tickets.