Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

BaseObservable — Extracting lifecycle and attribute change observability from `Y.Base` #168

Closed
wants to merge 20 commits into from

5 participants

@ericf
Owner

This extracts Y.BaseObservable, an extension for Y.BaseCore, from Y.Base.

By extracting the lifecycle and attribute change observability features, BaseCore subclasses have the potential to mix these features back in at runtime. These changes (and probably more) are needed to create the Y.Model.Base class and Y.Model.Observable extension.

I ran the base unit test and they all pass; additionally, I ran app's and a few other higher-level components to make sure I didn't introduce any gaps or regressions.

Running Locally

I explicitly did not commit the build files or the Loader metadata update, when trying out these changes locally, do the following:

$ cd src/attribute/ && shifter
$ cd ../base/ && shifter
$ cd ../yui/ && shifter

Todos

There are several things that still have to be done before this is merged in. Many of these came up in a code review of this Pull Request.

  • Determine if `Y.BaseObservable` can be mixed into a `Y.BaseCore` subclass at runtime.

  • Try implementing `Y.Model.Base` and `Y.Model.Observable` on this structure.

  • Move Attribute's `_protecteAttrs()` prototype method to a static utility method on the `Y.Attribute` constructor function.

  • Have `Y.BaseObservable` not mix `Y.Attribute` as a whole, instead:

    • Y.Base will itself mix-in Y.AttributeExtras before Y.BaseObservable.

    • Investigate whether Y.Model.Base should itself mix-in Y.AttributeExtras.

  • Remove `Base._buildCfg = ` from `base-build`:

    • Create a separate object used for Base's config that's a copy of BaseCore's.

  • Move the `_ATTR_CFG_HASH` computation into `base-build`.

  • Naming: I kind of like "observable" better, e.g. `Y.BaseCore` and `Y.BaseObservable`. This should trickle down to `Y.AttributeObservable` too.

  • Figure out correct yuidoc tags to use to make the API docs right (possibly a bug in yuidocjs).

ericf added some commits
@ericf ericf Move Base.js to BaseEvents.js 2d9f814
@ericf ericf Extract BaseEvents from Base.
Move the observablility of `Y.Base`'s lifecycle and attribute changes
into `Y.BaseEvents`, an extension for `Y.BaseCore`.
f1544a1
@ericf ericf Update `base` module and submodule metadata to include `base-events`. b1e13ff
src/base/js/Base.js
((59 lines not shown))
* @method _attrCfgHash
* @private
*/
_attrCfgHash: function() {
return Base._ATTR_CFG_HASH;
- },
@ericf Owner
ericf added a note

Having this method on Y.Base may affect the ability to mix in Y.BaseEvents into a Y.BaseCore subclass at runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/base/js/BaseEvents.js
((9 lines not shown))
+
+ DESTROY = "destroy",
+ INIT = "init",
+
+ BUBBLETARGETS = "bubbleTargets",
+ _BUBBLETARGETS = "_bubbleTargets",
+
+ Attribute = Y.Attribute,
+ AttributeEvents = Y.AttributeEvents;
+
+ /**
+ Provides an augmentable implementation of lifecycle and attribute events for
+ `BaseCore`.
+
+ @class BaseEvents
+ @extensionfor BaseCore
@ericf Owner
ericf added a note

This is currently causing yuidoc issues. Adding @for Base clears up Y.Base's docs, but leaves Y.BaseEvents without any "own" methods, events, properties.

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

@sdesai This is the initial work I've done to extract Y.BaseEvents from Y.Base. There is still more I want to do to make sure this services the needs of Y.Model.Base and Y.Model.Events. Let me know if anything stands out to you…

@lsmith

I wonder if this is similar to the DT class extensions, in that I included @for DataTable.Base in the docs so the methods would show up where they were most likely to be searched for. The module description for the class extensions include a note that the API docs are in DataTable, since otherwise they appear empty. (e.g. http://yuilibrary.com/yui/docs/api/classes/DataTable.Mutable.html)

@ericf
Owner

@lsmith Yup, this is the same thing I'm seeing. I guess we can sort that out when @davglass get's back and determine if there's something we want yuidoc to do differently or not.

src/base/js/Base.js
@@ -97,29 +72,29 @@
* @static
* @private
*/
- Base._ATTR_CFG = Attribute._ATTR_CFG.concat("cloneDefaultValue");
+ Base._ATTR_CFG = Y.BaseCore._ATTR_CFG.concat(Y.BaseEvents._ATTR_CFG);
Base._ATTR_CFG_HASH = Y.Array.hash(Base._ATTR_CFG);
@ericf Owner
ericf added a note

I'm pretty sure _ATTR_CFG and _ATTR_CFG_HASH should be aggregated by Y.Base.create() and Y.Base.mix(). Looking at Y.Base._buildCfg, I see the following:

Base._buildCfg = {
    custom: {
        ATTRS: function (prop, r, s) { /* ... */ },
        _NON_ATTRS_CFG: arrayAggregator
    }
};

It seems natural to add _ATTR_CFG and possibly _ATTR_CFG_HASH to this set. This way, you could mix Y.Base.Events (which wants to add things to _ATTR_CFG) to a Y.Base.Core subclass at runtime via Y.Base.mix().

Since _ATTR_CFG_HASH depends on _ATTR_CFG being fully aggregated, it would be brittle to rely on object property order for its function to be called after _ATTR_CFG's :-/

@ericf Owner
ericf added a note

The implementation I ended up with is in d92409c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@ericf ericf Update `Y.Base.create/mix` to work with `Y.BaseCore`.
This allows BaseCore to be the root Base-based superclass enabling the
ability to mix in BaseEvents at runtime. The following is now possible:

    Y.Foo = Y.Base.create('foo', Y.BaseCore, []);

    // And...

    Y.Bar = Y.Base.create('bar', Y.BaseCore, [Y.BaseEvents]);

    // Or...

    Y.Baz = Y.Base.create('baz', Y.BaseCore, []);
    Y.Base.mix(Y.Baz, [Y.BaseEvents]);
d92409c
@ericf
Owner

@sdesai I'd like to get this in 3.x, but would like you to review it first. This is a precursor to #2532429, and @caridy might want to use the new capabilities this provides.

@caridy
Owner

@sdesai the idea is to try to use this feature on the new mojito prototype we are building during the current cycle :)

@sdesai

Will take a look this week.

@sdesai

Sorry about the delay looking into this. I'm just going to put it in the next sprint, so it gets done.

ericf added some commits
@ericf ericf Merge branch 'master' into base-events
Conflicts:
	src/base/base-base.properties
	src/base/build.xml
	src/base/tests/base-tests.js
547702f
@ericf ericf Update Base's build.json, and remove old base-events Ant build files. 0546dd9
@ericf
Owner

Updated the Todos list in the Pull Request description based on feedback from @sdesai when we had a code review.

ericf added some commits
@ericf ericf Move Attribute's `_protectAttrs()` method to a static utility method.
This moves the protected `_protectAttrs()` method to a static utility
method on `Y.AttributeCore` and `Y.Attribute`.
19ba4d1
@ericf ericf Move hack to fix Attribute's IE Node clone issue down to AttributeCore. 8ced7fd
@ericf ericf Deprecate AttributeComplex and move its overrides into AttributeCore. b346ca0
@ericf ericf Change BaseEvents to mix AttributeEvents and Base to mix AttributeExtras
The reduces dependencies of BaseEvents, but does introduce the fact that
mixing BaseEvents into BaseCore does not equal the functionality of
Base. This is because Base now explicitly mixes in AttributeExtras.
bfcf08c
@ericf ericf Give BaseCore and Base their own `_buildCfg` objects. a4cc1a7
@ericf ericf Cache computation of Base/BaseCore's `_ATTR_CFG_HASH`.
A Base/BaseCore-based class will now compute its `_ATTR_CFG_HASH` on
demand, when it is needed. If an extension is mixed in via
`Y.Base.mix()`, then the cached hash will be nulled-out.
755e200
@ericf ericf Move AttributeEvents.js -> AttributeObservable.js. 36156ce
@ericf ericf Rename AttributeEvents -> AttributeObservable and module names.
This renames:

* Y.AttributeEvents -> Y.AttributeObservable
* attribute-events -> attribute-observable
1ba3973
@ericf ericf Move BaseEvents.js to BaseObservable.js 578a93f
@ericf ericf Rename BaseEvents -> BaseObservable.
This renames:

* Y.BaseEvents -> Y.BaseObservable
* base-events -> base-observable
a862773
@ericf
Owner

Note: Travis is lying, this does actually pass all tests, I just decided against checking in the build files for the sake of the diff.

@davglass
Owner
@ericf
Owner

It has been determined that the API documentation anomalies are issues with YUIDoc that will be reported and fixed there.

@ericf
Owner

I am going to merge this into the 3.x branch today. /cc @sdesai

@ericf
Owner

This has been merged in 3.x.

@ericf ericf closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 15, 2012
  1. @ericf

    Move Base.js to BaseEvents.js

    ericf authored
Commits on Jun 22, 2012
  1. @ericf

    Extract BaseEvents from Base.

    ericf authored
    Move the observablility of `Y.Base`'s lifecycle and attribute changes
    into `Y.BaseEvents`, an extension for `Y.BaseCore`.
  2. @ericf
Commits on Jun 25, 2012
  1. @ericf

    Update `Y.Base.create/mix` to work with `Y.BaseCore`.

    ericf authored
    This allows BaseCore to be the root Base-based superclass enabling the
    ability to mix in BaseEvents at runtime. The following is now possible:
    
        Y.Foo = Y.Base.create('foo', Y.BaseCore, []);
    
        // And...
    
        Y.Bar = Y.Base.create('bar', Y.BaseCore, [Y.BaseEvents]);
    
        // Or...
    
        Y.Baz = Y.Base.create('baz', Y.BaseCore, []);
        Y.Base.mix(Y.Baz, [Y.BaseEvents]);
Commits on Sep 26, 2012
  1. @ericf

    Merge branch 'master' into base-events

    ericf authored
    Conflicts:
    	src/base/base-base.properties
    	src/base/build.xml
    	src/base/tests/base-tests.js
  2. @ericf
Commits on Oct 9, 2012
  1. @ericf

    Move Attribute's `_protectAttrs()` method to a static utility method.

    ericf authored
    This moves the protected `_protectAttrs()` method to a static utility
    method on `Y.AttributeCore` and `Y.Attribute`.
Commits on Oct 10, 2012
  1. @ericf
  2. @ericf
  3. @ericf

    Change BaseEvents to mix AttributeEvents and Base to mix AttributeExtras

    ericf authored
    The reduces dependencies of BaseEvents, but does introduce the fact that
    mixing BaseEvents into BaseCore does not equal the functionality of
    Base. This is because Base now explicitly mixes in AttributeExtras.
  4. @ericf
Commits on Oct 12, 2012
  1. @ericf

    Cache computation of Base/BaseCore's `_ATTR_CFG_HASH`.

    ericf authored
    A Base/BaseCore-based class will now compute its `_ATTR_CFG_HASH` on
    demand, when it is needed. If an extension is mixed in via
    `Y.Base.mix()`, then the cached hash will be nulled-out.
  2. @ericf
  3. @ericf

    Rename AttributeEvents -> AttributeObservable and module names.

    ericf authored
    This renames:
    
    * Y.AttributeEvents -> Y.AttributeObservable
    * attribute-events -> attribute-observable
  4. @ericf
  5. @ericf

    Rename BaseEvents -> BaseObservable.

    ericf authored
    This renames:
    
    * Y.BaseEvents -> Y.BaseObservable
    * base-events -> base-observable
Commits on Oct 22, 2012
  1. @ericf
  2. @ericf
  3. @ericf
  4. @ericf

    Update Base's change history.

    ericf authored
Something went wrong with that request. Please try again.