Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 20 commits into
from

Conversation

Projects
None yet
5 participants
Owner

ericf commented Jun 22, 2012

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 Jun 15, 2012

@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

@ericf ericf commented on an outdated diff Jun 22, 2012

src/base/js/Base.js
* @method _attrCfgHash
* @private
*/
_attrCfgHash: function() {
return Base._ATTR_CFG_HASH;
- },
@ericf

ericf Jun 22, 2012

Owner

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

@ericf ericf commented on an outdated diff Jun 22, 2012

src/base/js/BaseEvents.js
+
+ 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

ericf Jun 22, 2012

Owner

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.

Owner

ericf commented Jun 22, 2012

@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…

Contributor

lsmith commented Jun 22, 2012

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)

Owner

ericf commented Jun 22, 2012

@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.

@ericf ericf commented on an outdated diff Jun 22, 2012

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

ericf Jun 22, 2012

Owner

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

ericf Jun 25, 2012

Owner

The implementation I ended up with is in d92409c

@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
Owner

ericf commented Aug 30, 2012

@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.

Owner

caridy commented Aug 31, 2012

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

Contributor

sdesai commented Sep 4, 2012

Will take a look this week.

Contributor

sdesai commented Sep 20, 2012

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 Sep 26, 2012

@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
Owner

ericf commented Oct 8, 2012

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

ericf added some commits Oct 9, 2012

@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
Owner

ericf commented Oct 12, 2012

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.

Owner

davglass commented Oct 12, 2012

I'm not sure why my scripts aren't picking it up, I'll ping the Travis
guys to make sure the Env is getting set.

Owner

ericf commented Oct 22, 2012

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

Owner

ericf commented Oct 22, 2012

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

Owner

ericf commented Oct 22, 2012

This has been merged in 3.x.

@ericf ericf closed this Oct 22, 2012

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