Results 1 to 4 of 4

Thread: Component without visual

  1. #1
    Sencha User
    Join Date
    Feb 2011
    Location
    Düsseldorf, Germany
    Posts
    599
    Answers
    35

    Default Component without visual

    Hi there,

    I would like to create a class with all the pros an Ext.Component gives me.
    But I do not need a visual appearance.

    So I thought I could use AbstractComponent, but it gives me the error of a missing itemId.

    Code:
    Ext.define('App.view.components.AndroidAudio', {
        extend: 'Ext.AbstractComponent',
        xtype: 'myaudio',
    
    
        config: {
            /**
             * @cfg {string} url
             */
            url: null,
            /**
             * @cgf {number} volume
             */
            volume: null,
    
    
            /**
             * @cgf {object} media object
             *
             * @private
             */
            media: null
        },
    
    
        cachedConfig: {
            baseUrl: 'resources/mp3/'
        },
    
    
        initialize: function () {
            this.callParent(arguments);
    
    
            App.messageBus.on('playertoggle', this.toggleRunning, this);
        },
    
    
        toggleRunning: function (state) {
            var media = this.getMedia();
    
    
            switch(state){
                case 'play':
                    media.play();
                    break;
                case 'close':
                    this.setUrl(null);
                    break;
                default:
                    media.pause();
            }
        }
    });
    Because its not working for me that way I am currently using Ext.Component with hidden:true.
    Is there a better way?

    I also tried to add

    Code:
    constructor: function(config) {this.initConfig(config)}

  2. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,379
    Answers
    3997

    Default

    Quote Originally Posted by Kurt001 View Post
    I would like to create a class with all the pros an Ext.Component gives me.
    What do you mean by this?
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

  3. #3
    Sencha User
    Join Date
    Feb 2011
    Location
    Düsseldorf, Germany
    Posts
    599
    Answers
    35

    Default

    Ext.Component is a class, that gets instantiated (supporting lazy) with config and is being handled by ST.
    So if I destroy a view, the component inside is destroyed.

    But my class is not supposed to show something (it's supposed to be a phonegap audio container).
    I do not want to use the ST Ext.Audio, but still want to add it to different views.

    Currently I am using Ext.Component and I can wonderfully use apply and update as well as react to events and cast such.

  4. #4
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,379
    Answers
    3997

    Default

    The issue is Ext.Component (which extends Ext.AbstractComponent also) does many thing you may not need so you are opting into a performance trip. TO get the apply/update methods, all you have to do is execute initConfig in the class' constructor:

    Code:
    Ext.define('MyClass', {
        config : {
            foo : 'bar'
        },
    
        constructor : function(config) {
            this.initConfig(config);
            this.callParent([config]);
        }
    });
    To add events, just need to include the Observable mixin:

    Code:
    Ext.define('MyClass', {
        mixins: ['Ext.mixin.Observable'],
        
        config : {
            foo : 'bar'
        },
    
        constructor : function(config) {
            this.initConfig(config);
            this.callParent([config]);
        }
    });
    Now you have getters/setters/updaters/appliers and you can listen and fire events on that class.
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

Tags for this Thread

Posting Permissions

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