View Full Version : [2.0b1][CLOSED] Store update event not fired if value is object

17 Oct 2007, 8:08 AM
Not sure if this is a bug or intentional but, due to this change in record.js:

// version 1.1
set : function(name, value){
if(this.data[name] == value){

// version 2.0
set : function(name, value){
if(String(this.data[name]) == String(value)){
you no longer get an update event if you store an object in a record and then change it to another object. See the firebug session below:

>>> // Create a store and add a listener to the update event
>>> s = new Ext.data.SimpleStore({fields: ['value'], data: [['one']]})
>>> s.on('update', function () {console.log('got update event');})

>>> // Change the record to a string - get update event
>>> s.getAt(0).set('value', 'two')
got update event

>>> // Change the record to an object - get update event
>>> s.getAt(0).set('value', {a: 1})
got update event

>>> // Change the record to a different object - don't get update event
>>> s.getAt(0).set('value', {a: 2})
Perhaps I shouldn't be storing objects in records? I've found SimpleStore useful in the past as a store for key/value pairs with built-in change notifications.

17 Oct 2007, 9:24 AM
Indeed I encountered this problem also.
Look the source there is a string cast on update event firing, to verify data has changed or note, something like :
if (String(value) == String(oldValue)) { doNotFireUpdate ; }

An object casted to a string gives "[Object object]", so the comparison is always true.

I dunno if it's wanted by Jack ?

20 Oct 2007, 7:47 AM
While you can put any type of data into a field (including an object) if you don't supply a type (it defaults to a string), it is definitely not valid so you may need to alter code. We'd be more open to discussing enhancements to support an object data type if it wasn't reported in bugs.

23 Oct 2007, 6:39 AM
Fair enough. I'd missed the docs for Record.create showing the available data types and so, seeing the description for set, I assumed values of type Object were supported.:

Record.set( String name, Object value ) : voidI've since discovered Ext.util.MixedCollection() which is a better fit for my usage.

Thanks for responding anyway. I'll mark this one as closed.