Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Ext JS Premium Member
    Join Date
    Mar 2009
    Posts
    47
    Vote Rating
    1
    uzver is on a distinguished road

      1  

    Default [CLOSED-EXTJSIV-303] Add to Ext.data.Model update/datachanged event

    [CLOSED-EXTJSIV-303] Add to Ext.data.Model update/datachanged event


    subj

  2. #2
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,987
    Vote Rating
    649
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    We decided not to implement this for 2 reasons:

    1) It's not really a common use case to want to listen to an event on a single record, rather you'll want to listen to changes on a group of records.

    2) Possible performance implications, records get updated quite a lot, as well as being recreated behind the scenes, which makes it difficult to main the events.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  3. #3
    Sencha User
    Join Date
    Jan 2012
    Posts
    25
    Vote Rating
    0
    grnadav is on a distinguished road

      0  

    Default too bad

    too bad


    It's a real usecase for us. No normal workaround either...

  4. #4
    Ext JS Premium Member burnnat's Avatar
    Join Date
    Jun 2011
    Posts
    418
    Vote Rating
    61
    burnnat is a jewel in the rough burnnat is a jewel in the rough burnnat is a jewel in the rough burnnat is a jewel in the rough

      0  

    Default


    I do have a workaround for this issue - it's not the prettiest solution in the world, but it does work, at least for me. The basic principle is to use Ext.data.Model#join to fool the record into thinking that your listener class is one of the parent stores for the model record, which will then be notified when that particular record is edited. Although the documentation says that Ext.data.Model.join() expects the parameter to be a Store, you don't actually have to extend the Ext.data.Store class. Instead, you just need to be sure to implement "afterEdit", "afterReject", and "afterCommit" methods on your listener class, and they will be called appropriately by the record. Just be sure to unjoin() when you're done with the listener!

    Here's a simple example:
    Code:
    Ext.define('User', {
        extend: 'Ext.data.Model',
        fields: ['id', 'name']
    });
    
    Ext.define('Listener', {
        constructor: function(record) {
            record.join(this);
        },
        
        afterEdit: function(record) {
            console.log('edit');
        },
        
        afterReject: function(record) {
            console.log('reject');
        },
        
        afterCommit: function(record) {
            console.log('commit');
        }
    });
    
    var user = Ext.create('User', {
        id: 1,
        name: 'John'
    });
    
    var listener = Ext.create('Listener', user);
    
    user.set('name', 'Joe');
    Note that I'm using this with ExtJS 4.1.0 ... I don't know if it will work on other versions or not.

  5. #5
    Sencha User
    Join Date
    Mar 2012
    Posts
    24
    Vote Rating
    0
    skyboyer is on a distinguished road

      0  

    Default


    Maybe it make sense to add configuration item for making model observable?
    So if it is needed model will have events

Similar Threads

  1. Replies: 5
    Last Post: 6 Apr 2012, 1:38 AM
  2. Replies: 9
    Last Post: 5 Sep 2011, 4:13 PM
  3. Store does not fire "datachanged" event when data is updated
    By tfrugia in forum Sencha Touch 1.x: Discussion
    Replies: 1
    Last Post: 17 Dec 2010, 12:40 PM
  4. # [CLOSED-471723] Why update event is handler many times on Ext.data.Store ?
    By rimbaudsolaris in forum Ext 3.x: Help & Discussion
    Replies: 13
    Last Post: 2 Jun 2010, 11:35 AM
  5. Replies: 2
    Last Post: 9 Jan 2008, 6:22 AM

Thread Participants: 4