Results 1 to 5 of 5

Thread: [INFOREQ]allow singleton as mixins

    Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Sencha User
    Join Date
    Nov 2008
    Location
    Lyon, France
    Posts
    229

    Default [INFOREQ]allow singleton as mixins

    Hi all
    This is not a bug, but I am wondering if it would not make sense to allow singleton to be utilized as mixins.

    This change (ext-core-debug, l. 2656):
    Code:
       mixin: flexSetter(function(name, cls) {
               // var mixinPrototype = cls.prototype,
                var mixinPrototype = cls.prototype ? cls.prototype : cls,
                    myPrototype = this.prototype,
                    i;
    ...
    would allow it.

    Cheers and good luck with the release
    Christophe

  2. #2
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,258

    Default

    In what kind of scenario would you use this?
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  3. #3
    Sencha User
    Join Date
    Nov 2008
    Location
    Lyon, France
    Posts
    229

    Default

    Yep, sure.
    An example from my xForms application:
    I have one singleton where a couple of xml-related attributes and functionalities are defined (xml namespace definition, parsing, serializing, xslt transformation, ...). Those methods and properties are shared accross different xForms-aware objects (like xforms instances, models and fields) and hence injected as mixins.

    I could use the @createdFn from Ext.ClassManager.create to add something like :
    function() { myNewSingletonFromClass = new this() ... } if the change I am proposing does not fit the code base, but I think it would be clearer to take advantage of the Ext.define ... singleton = true ... scenario.

    Cheers
    Christophe

  4. #4
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,258

    Default

    Right, but since it's a singleton, why not just call the methods directly? What benefit do you get from mixing them in to the current class?
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  5. #5
    Sencha User
    Join Date
    Nov 2008
    Location
    Lyon, France
    Posts
    229

    Default

    Simply because of "this" ; )

    You might want to be able to inject default methods into Ext components via mixins and keep specific methods (with the same name) for more specialized components (that would not be overriden by the mixin).

    A concrete example from my app:
    bind: a method allowing to bind Ext components with xml elements (change of the xml element value or state (readonly, visiblity, validation) is reflected in any binded component and vice-versa). The default bind method is defined in a singleton and mixed into all xforms aware components. However more specific bind mechanisms need to be implemented for some extra components (e.g. binding an HtmlEditor will need some special care compared to a simple textField).

    At the same time, I also need to invoke the same methods from elsewere in the app (hence the singleton).

    I thought Mixins were introduced to handle such cases.
    Cheers
    C.

Similar Threads

  1. [CLOSED]Ext.AbstractComponent mixins
    By gevik in forum Ext:Bugs
    Replies: 5
    Last Post: 28 Feb 2011, 9:56 PM
  2. Replies: 2
    Last Post: 25 Feb 2011, 7:17 AM
  3. Singleton object
    By asagala in forum Ext 3.x: Help & Discussion
    Replies: 9
    Last Post: 7 Oct 2009, 6:30 AM

Posting Permissions

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