Results 1 to 2 of 2

Thread: How to inject reference to application or event bus with Deft?

  1. #1
    Sencha User
    Join Date
    Oct 2011
    Location
    Vancouver, Canada
    Posts
    157
    Answers
    5

    Default How to inject reference to application or event bus with Deft?

    My Deft viewcontroller needs to fire application-wide events.

    How do I inject the app or app eventbus into a viewcontroller using deft?

    Please do not say use a global reference to the application. That defeats the point of using a dependency injection.

  2. #2
    Sencha User
    Join Date
    Oct 2011
    Location
    Vancouver, Canada
    Posts
    157
    Answers
    5

    Default

    Quote Originally Posted by el_chief View Post
    My Deft viewcontroller needs to fire application-wide events.

    How do I inject the app or app eventbus into a viewcontroller using deft?

    Please do not say use a global reference to the application. That defeats the point of using a dependency injection.
    The answer is don't worry about the application bus, and just make your own:

    Code:
    Ext.define('My.app.EventBus', {
        mixins:{
    	observable: 'Ext.util.Observable'
        },
        constructor: function(){
    	this.mixins.observable.constructor.call(this);
        }
    });
    Then configure it with Deft:

    Code:
    Deft.ioc.Injector.configure({
    	    'eventBus':'My.app.EventBus' /* is a singleton, by default*/
    	});
    Then inject it in a controller:

    Code:
    Ext.define('My.controller.contacts.Form', {
        extend: 'Deft.mvc.ViewController',
        mixins:  ['Deft.mixin.Injectable'],
        inject:   ['eventBus'],
    
    
        config: {
    	eventBus: null
        },
    
    
        init: function(config){
    	this.initConfig(config);
    
    
    	this.getEventBus().on('someEvent', function(){ });
    
    	this.callParent(arguments);
        }
    });

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •