Agility 'Event' object

44 views
Skip to first unread message

defl...@gmail.com

unread,
May 9, 2013, 2:05:23 PM5/9/13
to agil...@googlegroups.com
Hello. In the following example how it is possible to access appended object ? I tried e.target, bu it returns some strange object and i have no idea how to use it.

var list = $$({}, '<div><a href="">click</a></div>', {
  'click a': function(){
    var object1 = $$({}, '<b>test</b>');
    this.append(obect1, 'div');
  },
  'append': function(e) {
    // if one wants to access object1 here ?
    var object1 = e.target; // wrong!
  }
});


rjo...@opdots.com

unread,
May 10, 2013, 8:50:18 AM5/10/13
to agil...@googlegroups.com
I'm not positive, but I think your overriding the append handler itself because it triggers your function without doing the append.

Try something like the following (I fixed the object1 name in the append itself, too). "this" should have the object being appended here.

var list = $$({}, '<div><a href="">click</a></div>', { 'click a': function(){ var object1 = $$({}, '<b>test</b>'); this.append(object1); }, 'pre:appended': function(e) { // can be pre: or post: console.log( e ); console.log( this ); } });

Here's the applicable code from agility.js that implements that tigger:

      // Triggered after child obj is appended to container
      _append: function(event, obj, selector){
        obj.trigger('pre:appended');
        this.view.$(selector).append(obj.view.$());
        obj.trigger('post:appended');
      },

defl...@gmail.com

unread,
May 11, 2013, 3:34:42 AM5/11/13
to agil...@googlegroups.com
I took this 'append' as event from todomvc example (http://todomvc.com/architecture-examples/agilityjs/js/app.js), but now i checked once again Agility.js docs and
did found that it should be not 'append', but instead 'add' event. So i change it to 'add':

var list = $$({}, '<div><a href="">click</a></div>', {
  'click a': function(){  this.append($$({}, '<b>test</b>'), 'div');  },
  'add': function(e) {  // ...  }
});

And that 'add' handler does not get called at all.
Also, i tried your suggestion and used 'pre:appended', and it is also doesn't called.
Then i checked source at github: https://github.com/arturadib/agility/blob/master/agility.js and it looks like 'append' is currently correct event name, so api docs is wrong/stale ?



четверг, 9 мая 2013 г., 22:05:23 UTC+4 пользователь defl...@gmail.com написал:

defl...@gmail.com

unread,
May 11, 2013, 3:46:20 AM5/11/13
to agil...@googlegroups.com
Hello again, i browsed source code and test and found answer on my question.
This seems that currently 'append' is correct name for the Agility event, which is called when new object is added to container.
Also object that added is itself available as second argument to callback function, here is correct code:

var list = $$({}, '<div><a href="">click</a></div>', {
  'click a': function(){
    var object1 = $$({}, '<b>test</b>');
    this.append(obect1, 'div');
  },
  'append': function(event, object, selector) {
    // here is object is object that added
    // and selector is string 'div'
  }
});


четверг, 9 мая 2013 г., 22:05:23 UTC+4 пользователь defl...@gmail.com написал:
Hello. In the following example how it is possible to access appended object ? I tried e.target, bu it returns some strange object and i have no idea how to use it.

Robert Jones

unread,
May 11, 2013, 10:11:53 AM5/11/13
to agil...@googlegroups.com
You're right... I referenced a really old version. Glad you figured that one out.
Reply all
Reply to author
Forward
0 new messages