Skip to content

Instantly share code, notes, and snippets.

@lsmith
Created October 21, 2011 22:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lsmith/1305121 to your computer and use it in GitHub Desktop.
Save lsmith/1305121 to your computer and use it in GitHub Desktop.
// For Y.Foo
// Class extensions that will be used in the base class
function ExtA() {}
...
Y.namespace('Foo').ExtA = ExtA;
// Base Class definition
function FooBase() {}
...
Y.Foo.Base = Y.Base.create('foo', Y.Base, [FooBase, Y.Foo.ExtA]);
Y.Foo = Y.mix( Y.Base.create('foo', Y.Foo.Base, []), Y.Foo, true );
// Optional class extensions
function ExtB() {}
...
Y.Foo.ExtB = ExtB;
Y.Base.mix(Y.Foo, [ExtB]);
// If there aren't any other class extensions used to define the base class
Y.namespace('Foo').Base = Y.Base.create('foo', Y.Base, [], { proto }, { statics });
Y.Foo = Y.mix( Y.Base.create('foo', Y.Foo.Base, []), Y.Foo, true );
// Alternate for constructing the base class with extensions:
Y.Foo.Base = Y.Base.create('foo', Y.Base, [], { proto }, { statics });
Y.Base.mix(Y.Foo.Base, [ Y.Foo.ExtA ]);
Y.Foo = Y.mix( Y.Base.create('foo', Y.Foo.Base, []), Y.Foo, true );
@lsmith
Copy link
Author

lsmith commented Dec 13, 2011

Currently, this pattern runs into trouble when the extensions that will define core behavior include static properties. Base.create only aggregates ATTRS for Base subclasses and ATTRS and HTML_PARSER (maybe a few more) for Widget subclasses onto the generated class.

It's awkward and not intuitive to refer to statics on a class extension, and Base.create (as of this writing) looks only on the superclass axis for what statics to aggregate, so there's no easy way to keep the extensions decoupled from the Base.create()d class implementation. Today, you must use the alternate pattern to copy statics from the extensions, but this means changes in the extension need to be mirrored in the code that consumes it (ick).

This issue is being tracked here: http://yuilibrary.com/projects/yui3/ticket/2531567

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment