Opened 10 years ago

Closed 9 years ago

Last modified 9 years ago

#14067 closed enhancement (fixed)

ItemFileReadStore: Allow a function to be used as a query paramiter

Reported by: bag Owned by: Jared Jurkiewicz
Priority: high Milestone: 1.8
Component: Data Version: 1.6.1
Keywords: Cc: [email protected]
Blocked By: Blocking:

Description (last modified by bill)


The attached patch is a really simple (3 lines) change which allows a user to specify a true/false function as a query parameter for an ItemFileReadStore?.

Allowing this makes it possible for a user to query a datastore based on significantly more complex parameters. The most common situation this is useful in is probably when a user needs to query the datastore based on a numeric range (col_x is less than 10 kinda stuff).

With the change its possible to do this with the syntax:

someDataStore.setQuery({"col_x" : function(v){return (v<10);});

Although far more complicated checks could also be implemented if they were needed.

The change is implemented in the _containsValue method and consist of a 3rd clause to the if statement that checks if the value being matched on is a function and if so runs that function with the current fields value as its parameter. The return value of this function is used to set the matched variable.

The code change in full (on line 217) is just:

else if(typeof value === "function"){
	return value(possibleValue);

I created the change as part of a personal project earlier this week and thought other people may also find the feature useful.

Thanks :)

Attachments (1)

ItemFileReadStore.diff (384 bytes) - added by bag 10 years ago.
Diff file with change suggested in ticket

Download all attachments as: .zip

Change History (7)

Changed 10 years ago by bag

Attachment: ItemFileReadStore.diff added

Diff file with change suggested in ticket

comment:1 Changed 10 years ago by bill

Description: modified (diff)
Owner: changed from Kris Zyp to Jared Jurkiewicz

Given that ItemFileReadStore is essentially deprecated in favor of, which can already take a function as the query, this is probably a wontfix, but passing on to Jared.

There's also a question of whether bag has a CLA, although I guess the change is trivial enough to accept without one.

comment:2 Changed 10 years ago by bag


I'd emailed a CLA shortly before posting, although had not yet heard anything back. Also as bill said the fix is pretty trivial (basically just an if and a function call) so it should hopefully be unnecessary.

Also I'd already been warned in the #dojo channel that the change would probably be "wontfix"ed due to the deprecation of the ItemFileReadStore? etc. I just thought I may as well submit the code anyway and let you guys decided :)

Last edited 10 years ago by bag (previous) (diff)

comment:3 Changed 9 years ago by Jared Jurkiewicz

In [27225]:

Added in support for function passing as value \!strict refs #14067

comment:4 Changed 9 years ago by Jared Jurkiewicz

In [27226]:

Added in support for function passing as value \!strict refs #14067

comment:5 Changed 9 years ago by Jared Jurkiewicz

Resolution: fixed
Status: newclosed

Minor if check added. Enhancement request fixed.

comment:6 Changed 9 years ago by bill

Milestone: tbd1.8
Note: See TracTickets for help on using tickets.