Dojo 1.6 Stores interesting findings and potential Bug

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Dojo 1.6 Stores interesting findings and potential Bug

j105.rob
Maybe an issue, maybe a learning curve problem....

I have an Observable store that is comprised of a Caching store that uses a JRS and a Memory store.

I am observing a query in my widget for changes to the data.

When an item is added to the store via the store.add(), it goes thru the JRS up to the server and is added to the database and the newly inserted item is returned with additional properties created at insert time. This "new" item is added to the caching store properly, but since the caching store's add() (really put() underneath) only returns the id of the item added, the observable store's observation code:

whenFinished("add", function(object){
store.notify(object);
});

implemented as:

function whenFinished(method, action){
var original = store[method];
if(original){
store[method] = function(value){
if(inMethod){
// if one method calls another (like add() calling put()) we don't want two events
console.log("inMethod",method,results);
return original.apply(this, arguments);
}
inMethod = true;
try{
return dojo.when(original.apply(this, arguments), function(results){
action((typeof results == "object" && results) || value);
return results;
});
}finally{
inMethod = false;
}
};
}

prevents the "new" item from being returned since the results of the original.apply(this,arguments) is the id, which is not an object, but an integer, so the action((typeof results == "object" && results) || value); sends the client side item (the object that only has part of the item data, provided in this case via the "value") to the store.notify().

The problem is that I need the actual row (item) of data that is created by the insert process on the server side, not what I created on the client and passed to the server. The client side item is pretty much useless, and there is no way to get the item being send back in the response of the store.put(); if I use the current implementation of the observable store.

Thoughts?

________________________________________________________
Dojotoolkit: http://dojotoolkit.org
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api
Tutorials: http://dojotoolkit.org/documentation

[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: Dojo 1.6 Stores interesting findings and potential Bug

Simon Speich
I didn't really read your post careful enough, but if you want to force store.add to do a POST instead of a PUT you can force it to do so by doing:

store.add(newItem, {
   incremental: true
}
and return the newly created data.
Reply | Threaded
Open this post in threaded view
|

Re: Dojo 1.6 Stores interesting findings and potential Bug

neonstalwart
no offense but... if you read closer you'll see that's unrelated to the
question - by a long shot :)

ben...

On 7/15/2011 11:01 AM, Simon Speich wrote:

> I didn't really read your post careful enough, but if you want to force
> store.add to do a POST instead of a PUT you can force it to do so by doing:
>
> store.add(newItem, {
>     incremental: true
> }
> and return the newly created data.
>
> --
> View this message in context: http://dojo-toolkit.33424.n3.nabble.com/Dojo-1-6-Stores-interesting-findings-and-potential-Bug-tp3168934p3172217.html
> Sent from the Dojo Toolkit mailing list archive at Nabble.com.
> ________________________________________________________
> Dojotoolkit: http://dojotoolkit.org
> Reference Guide: http://dojotoolkit.org/reference-guide
> API Documentation: http://dojotoolkit.org/api
> Tutorials: http://dojotoolkit.org/documentation
>
> [hidden email]
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
________________________________________________________
Dojotoolkit: http://dojotoolkit.org
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api
Tutorials: http://dojotoolkit.org/documentation

[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: Dojo 1.6 Stores interesting findings and potential Bug

j105.rob
In reply to this post by Simon Speich
Thx for the reply Simon.

It was an issue with the Memory store. I fixed it by creating my own Memory store wrapper that clobbered the original memory store put() code.

It seems to me like the developers of the Memory store were only returning the id of the newly created item vs. the entire item was because the assumption is that you passed the item into the function and the only thing the function was changing about the item was the id; so why not just return the id.

The problem with that concept is when you are using a Memory store in a caching store with a JRS master. The data item passed to the server on the put/post "probably" is not what is returned; in my case the put/post only requires 3 of the 14 attributes to be present and the other attributes of the item are filled in at insert time and subsequently returned back to the client. That item with the 14 attributes is what I need..... not the 3 I sent initially, let alone just the id...

On Fri, Jul 15, 2011 at 11:01 AM, Simon Speich <[hidden email]> wrote:
I didn't really read your post careful enough, but if you want to force
store.add to do a POST instead of a PUT you can force it to do so by doing:

store.add(newItem, {
  incremental: true
}
and return the newly created data.

--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/Dojo-1-6-Stores-interesting-findings-and-potential-Bug-tp3168934p3172217.html
Sent from the Dojo Toolkit mailing list archive at Nabble.com.
________________________________________________________
Dojotoolkit: http://dojotoolkit.org
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api
Tutorials: http://dojotoolkit.org/documentation

[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


________________________________________________________
Dojotoolkit: http://dojotoolkit.org
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api
Tutorials: http://dojotoolkit.org/documentation

[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: Dojo 1.6 Stores interesting findings and potential Bug

Simon Speich
In reply to this post by neonstalwart
Mea culpa for spamming then...
Reply | Threaded
Open this post in threaded view
|

Re: Dojo 1.6 Stores interesting findings and potential Bug

neonstalwart
In reply to this post by j105.rob
if i'm not mistaken, the reason for returning the id is because that's what http://www.w3.org/TR/IndexedDB/#object-store-sync does and that's the way it's been specified in the store API - see dojo/store/api/Store.js

i think the fix would be to probably change
    whenFinished("put", function(object){
        store.notify(object, store.getIdentity(object));
    });

to be like
    whenFinished("put", function(id){
        dojo.when(store.get(id), function (object) {
            store.notify(object, id);
        });
    });

and similarly for "add".

did you file a ticket about this?  i think its a bug.

ben...

On 7/15/2011 11:13 AM, Rob Weiss wrote:
Thx for the reply Simon.

It was an issue with the Memory store. I fixed it by creating my own Memory store wrapper that clobbered the original memory store put() code.

It seems to me like the developers of the Memory store were only returning the id of the newly created item vs. the entire item was because the assumption is that you passed the item into the function and the only thing the function was changing about the item was the id; so why not just return the id.

The problem with that concept is when you are using a Memory store in a caching store with a JRS master. The data item passed to the server on the put/post "probably" is not what is returned; in my case the put/post only requires 3 of the 14 attributes to be present and the other attributes of the item are filled in at insert time and subsequently returned back to the client. That item with the 14 attributes is what I need..... not the 3 I sent initially, let alone just the id...

On Fri, Jul 15, 2011 at 11:01 AM, Simon Speich <[hidden email]> wrote:
I didn't really read your post careful enough, but if you want to force
store.add to do a POST instead of a PUT you can force it to do so by doing:

store.add(newItem, {
  incremental: true
}
and return the newly created data.

--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/Dojo-1-6-Stores-interesting-findings-and-potential-Bug-tp3168934p3172217.html
Sent from the Dojo Toolkit mailing list archive at Nabble.com.
________________________________________________________
Dojotoolkit: http://dojotoolkit.org
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api
Tutorials: http://dojotoolkit.org/documentation

[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest



________________________________________________________
Dojotoolkit: http://dojotoolkit.org
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api
Tutorials: http://dojotoolkit.org/documentation

[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

________________________________________________________
Dojotoolkit: http://dojotoolkit.org
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api
Tutorials: http://dojotoolkit.org/documentation

[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: Dojo 1.6 Stores interesting findings and potential Bug

j105.rob
@Ben - I did not yet, I was fishing for others' opinions first. I'll file one, can I reference this maillist thread? Or should I repost it all in the trac?

On Fri, Jul 15, 2011 at 11:38 AM, ben hockey <[hidden email]> wrote:
if i'm not mistaken, the reason for returning the id is because that's what http://www.w3.org/TR/IndexedDB/#object-store-sync does and that's the way it's been specified in the store API - see dojo/store/api/Store.js

i think the fix would be to probably change
    whenFinished("put", function(object){
        store.notify(object, store.getIdentity(object));
    });

to be like
    whenFinished("put", function(id){
        dojo.when(store.get(id), function (object) {
            store.notify(object, id);
        });
    });

and similarly for "add".

did you file a ticket about this?  i think its a bug.

ben...


On 7/15/2011 11:13 AM, Rob Weiss wrote:
Thx for the reply Simon.

It was an issue with the Memory store. I fixed it by creating my own Memory store wrapper that clobbered the original memory store put() code.

It seems to me like the developers of the Memory store were only returning the id of the newly created item vs. the entire item was because the assumption is that you passed the item into the function and the only thing the function was changing about the item was the id; so why not just return the id.

The problem with that concept is when you are using a Memory store in a caching store with a JRS master. The data item passed to the server on the put/post "probably" is not what is returned; in my case the put/post only requires 3 of the 14 attributes to be present and the other attributes of the item are filled in at insert time and subsequently returned back to the client. That item with the 14 attributes is what I need..... not the 3 I sent initially, let alone just the id...

On Fri, Jul 15, 2011 at 11:01 AM, Simon Speich <[hidden email]> wrote:
I didn't really read your post careful enough, but if you want to force
store.add to do a POST instead of a PUT you can force it to do so by doing:

store.add(newItem, {
  incremental: true
}
and return the newly created data.

--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/Dojo-1-6-Stores-interesting-findings-and-potential-Bug-tp3168934p3172217.html
Sent from the Dojo Toolkit mailing list archive at Nabble.com.
________________________________________________________
Dojotoolkit: http://dojotoolkit.org
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api
Tutorials: http://dojotoolkit.org/documentation

[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest



________________________________________________________
Dojotoolkit: http://dojotoolkit.org
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api
Tutorials: http://dojotoolkit.org/documentation

[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

________________________________________________________
Dojotoolkit: http://dojotoolkit.org
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api
Tutorials: http://dojotoolkit.org/documentation

[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest



________________________________________________________
Dojotoolkit: http://dojotoolkit.org
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api
Tutorials: http://dojotoolkit.org/documentation

[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: Dojo 1.6 Stores interesting findings and potential Bug

neonstalwart
if you can find a way to link to this thread then go ahead and link to it.  i assume kzyp will get the bug assigned to him and if he wants more he'll say so.

ben...

On 7/15/2011 12:24 PM, Rob Weiss wrote:
@Ben - I did not yet, I was fishing for others' opinions first. I'll file one, can I reference this maillist thread? Or should I repost it all in the trac?

On Fri, Jul 15, 2011 at 11:38 AM, ben hockey <[hidden email]> wrote:
if i'm not mistaken, the reason for returning the id is because that's what http://www.w3.org/TR/IndexedDB/#object-store-sync does and that's the way it's been specified in the store API - see dojo/store/api/Store.js

i think the fix would be to probably change
    whenFinished("put", function(object){
        store.notify(object, store.getIdentity(object));
    });

to be like
    whenFinished("put", function(id){
        dojo.when(store.get(id), function (object) {
            store.notify(object, id);
        });
    });

and similarly for "add".

did you file a ticket about this?  i think its a bug.

ben...


On 7/15/2011 11:13 AM, Rob Weiss wrote:
Thx for the reply Simon.

It was an issue with the Memory store. I fixed it by creating my own Memory store wrapper that clobbered the original memory store put() code.

It seems to me like the developers of the Memory store were only returning the id of the newly created item vs. the entire item was because the assumption is that you passed the item into the function and the only thing the function was changing about the item was the id; so why not just return the id.

The problem with that concept is when you are using a Memory store in a caching store with a JRS master. The data item passed to the server on the put/post "probably" is not what is returned; in my case the put/post only requires 3 of the 14 attributes to be present and the other attributes of the item are filled in at insert time and subsequently returned back to the client. That item with the 14 attributes is what I need..... not the 3 I sent initially, let alone just the id...

On Fri, Jul 15, 2011 at 11:01 AM, Simon Speich <[hidden email]> wrote:
I didn't really read your post careful enough, but if you want to force
store.add to do a POST instead of a PUT you can force it to do so by doing:

store.add(newItem, {
  incremental: true
}
and return the newly created data.

--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/Dojo-1-6-Stores-interesting-findings-and-potential-Bug-tp3168934p3172217.html
Sent from the Dojo Toolkit mailing list archive at Nabble.com.
________________________________________________________
Dojotoolkit: http://dojotoolkit.org
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api
Tutorials: http://dojotoolkit.org/documentation

[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest



________________________________________________________
Dojotoolkit: http://dojotoolkit.org
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api
Tutorials: http://dojotoolkit.org/documentation

[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

________________________________________________________
Dojotoolkit: http://dojotoolkit.org
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api
Tutorials: http://dojotoolkit.org/documentation

[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest




________________________________________________________
Dojotoolkit: http://dojotoolkit.org
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api
Tutorials: http://dojotoolkit.org/documentation

[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

________________________________________________________
Dojotoolkit: http://dojotoolkit.org
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api
Tutorials: http://dojotoolkit.org/documentation

[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: Dojo 1.6 Stores interesting findings and potential Bug

j105.rob
Created trac #13445.

http://bugs.dojotoolkit.org/ticket/13445

On Fri, Jul 15, 2011 at 1:08 PM, ben hockey <[hidden email]> wrote:
if you can find a way to link to this thread then go ahead and link to it.  i assume kzyp will get the bug assigned to him and if he wants more he'll say so.

ben...


On 7/15/2011 12:24 PM, Rob Weiss wrote:
@Ben - I did not yet, I was fishing for others' opinions first. I'll file one, can I reference this maillist thread? Or should I repost it all in the trac?

On Fri, Jul 15, 2011 at 11:38 AM, ben hockey <[hidden email]> wrote:
if i'm not mistaken, the reason for returning the id is because that's what http://www.w3.org/TR/IndexedDB/#object-store-sync does and that's the way it's been specified in the store API - see dojo/store/api/Store.js

i think the fix would be to probably change
    whenFinished("put", function(object){
        store.notify(object, store.getIdentity(object));
    });

to be like
    whenFinished("put", function(id){
        dojo.when(store.get(id), function (object) {
            store.notify(object, id);
        });
    });

and similarly for "add".

did you file a ticket about this?  i think its a bug.

ben...


On 7/15/2011 11:13 AM, Rob Weiss wrote:
Thx for the reply Simon.

It was an issue with the Memory store. I fixed it by creating my own Memory store wrapper that clobbered the original memory store put() code.

It seems to me like the developers of the Memory store were only returning the id of the newly created item vs. the entire item was because the assumption is that you passed the item into the function and the only thing the function was changing about the item was the id; so why not just return the id.

The problem with that concept is when you are using a Memory store in a caching store with a JRS master. The data item passed to the server on the put/post "probably" is not what is returned; in my case the put/post only requires 3 of the 14 attributes to be present and the other attributes of the item are filled in at insert time and subsequently returned back to the client. That item with the 14 attributes is what I need..... not the 3 I sent initially, let alone just the id...

On Fri, Jul 15, 2011 at 11:01 AM, Simon Speich <[hidden email]> wrote:
I didn't really read your post careful enough, but if you want to force
store.add to do a POST instead of a PUT you can force it to do so by doing:

store.add(newItem, {
  incremental: true
}
and return the newly created data.

--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/Dojo-1-6-Stores-interesting-findings-and-potential-Bug-tp3168934p3172217.html
Sent from the Dojo Toolkit mailing list archive at Nabble.com.
________________________________________________________
Dojotoolkit: http://dojotoolkit.org
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api
Tutorials: http://dojotoolkit.org/documentation

[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest



________________________________________________________
Dojotoolkit: http://dojotoolkit.org
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api
Tutorials: http://dojotoolkit.org/documentation

[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

________________________________________________________
Dojotoolkit: http://dojotoolkit.org
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api
Tutorials: http://dojotoolkit.org/documentation

[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest




________________________________________________________
Dojotoolkit: http://dojotoolkit.org
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api
Tutorials: http://dojotoolkit.org/documentation

[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

________________________________________________________
Dojotoolkit: http://dojotoolkit.org
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api
Tutorials: http://dojotoolkit.org/documentation

[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest



________________________________________________________
Dojotoolkit: http://dojotoolkit.org
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api
Tutorials: http://dojotoolkit.org/documentation

[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest