Handling an enyo.Model events by enyo.ModelController

bakbak
edited October 2013 in Enyo 2.4
How do I properly handle an enyo.Model events by enyo.ModelController? I'm trying to handle an event declared in the "events: {}" in the enyo.Model with the handler declared in the enyo.ModelController. Currently the event bubbling stops on the enyo.Source. How to tell the enyo.Model to propagate an event to the enyo.ModelController which uses this Model?

Comments

  • Short update: I want to fire an enyo.Model event inside the "success" callback passed as argument to the enyo.Model.commit() function.
  • Could somebody help me with this?
  • I'm not certain this is the best approach, perhaps Cole can explain it better than I can.

    But, I would probably just set some property on the model that indicated its success state and bind to that in the controller.
  • Hi @bak,

    The `success` callback for the `commit` method does not, by default, get called under the context of the model itself, but you could easily do one of 2 things:

    1. Use enyo.bind to bind the context of your `success` callback to the model so you can fire the event when you're ready or...
    2. Overload the `didFetch` method which will be called in the context of the model.

    Note that, as warned in previous announcements, there are changes afoot for the data layer kinds. There will be a lengthy writeup on what the changes are and why, but, just keep a lookout for that announcement.
  • Hi @clinuz,
    Thanks for the explanation. To fix my problem I will try to override didFetch/didCommit/didFail methods and to use a special property and an enyo.binding but I'm not sure if should it be the only way to handle the interaction between a model and its controller.

    The issue is that the controller isn't on the events bubbling path for its model (events bubbling stops on the enyo.Source) and in fact the controller has no chance to handle any events from the model (please correct me if I am wrong and tell me how to do it).
    If I'm not wrong I have a question: do you have any plans to add the enyo.ModelController to the enyo.Model's events bubbling path or I should learn to live without that feature?

    By the way: the `success` callback for the `commit` method does not get called under the context of the model itself but the model context is passed to that callback as a second parameter and I've tried to fire event on that model directly by calling "model.doMyEvent()".
Sign In or Register to comment.