Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

fixes and updates #248

Merged
merged 3 commits into from

2 participants

@clinuz
Owner

No description provided.

clinuz added some commits
@clinuz clinuz update docs, issue warning on non-unique kind name, fix naming test i…
…n enyo.kind

Enyo-DCO-1.1-Signed-off-by: Cole Davis <cole.davis@lge.com>
65beb1c
@clinuz clinuz convert to more efficient and straight forward context passing
Enyo-DCO-1.1-Signed-off-by: Cole Davis <cole.davis@lge.com>
c70577b
@clinuz clinuz add inheritance sanity unit test
Enyo-DCO-1.1-Signed-off-by: Cole Davis <cole.davis@lge.com>
61d3b35
@unwiredben unwiredben merged commit b5b8038 into enyojs:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 25, 2013
  1. @clinuz

    update docs, issue warning on non-unique kind name, fix naming test i…

    clinuz authored
    …n enyo.kind
    
    Enyo-DCO-1.1-Signed-off-by: Cole Davis <cole.davis@lge.com>
  2. @clinuz

    convert to more efficient and straight forward context passing

    clinuz authored
    Enyo-DCO-1.1-Signed-off-by: Cole Davis <cole.davis@lge.com>
  3. @clinuz

    add inheritance sanity unit test

    clinuz authored
    Enyo-DCO-1.1-Signed-off-by: Cole Davis <cole.davis@lge.com>
This page is out of date. Refresh to see the latest.
View
6 source/kernel/Object.js
@@ -110,12 +110,8 @@ enyo.kind({
// if there isn't a property do nothing
if (!enyo.exists(property)) return;
var fn = this[property + "FindAndInstance"];
- // if we have a callback bind it to the given object so that
- // it will be called under the correct context, if it has
- // already been bound this is harmless
- fn = enyo.exists(fn) && "function" === typeof fn? enyo.bind(this, fn): null;
// go ahead and call the enyo scoped version of this method
- return enyo.findAndInstance.call(this, property, fn);
+ return enyo.findAndInstance.call(this, property, fn, this);
},
//*@public
View
15 source/kernel/Oop.js
@@ -34,7 +34,7 @@ enyo.handleConcatenatedProperties = function (ctor, proto) {
//* @public
/**
Creates a JavaScript constructor function with a prototype defined by
- _inProps_.
+ _inProps_. __All constructors must have a unique name__.
_enyo.kind_ makes it easy to build a constructor-with-prototype (like a
class) that has advanced features like prototype-chaining (inheritance).
@@ -88,10 +88,11 @@ enyo.kind = function(inProps) {
// put in our props
enyo.mixin(ctor.prototype, inProps);
// alias class name as 'kind' in the prototype
- if (!name && kind && "string" === typeof kind) name = kind;
// but we actually only need to set this if a new name was used
// not if it is inheriting from a kind anonymously
if (name) ctor.prototype.kindName = name;
+ // this is for anonymous constructors
+ else ctor.prototype.kindName = base && base.prototype? base.prototype.kindName: "";
// cache superclass constructor
ctor.prototype.base = base;
// reference our real constructor
@@ -99,12 +100,18 @@ enyo.kind = function(inProps) {
// support pluggable 'features'
enyo.forEach(enyo.kind.features, function(fn){ fn(ctor, inProps); });
// put reference into namespace
- if (!enyo.getPath(name)) enyo.setPath(name, ctor);
+ if (name && !enyo.getPath(name)) enyo.setPath(name, ctor);
+ else if (name) {
+ enyo.warn("enyo.kind: " + name + " is already in use by another " +
+ "kind, all kind definitions must have unique names.");
+ }
return ctor;
};
/**
- Creates a Singleton
+ Creates a Singleton of a given kind with a given definition.
+ __The name property will be the instance name of the singleton
+ and must be unique__.
enyo.singleton({
kind: Control,
View
6 source/kernel/lang.js
@@ -248,7 +248,7 @@
was found and the second being the instance if it could be
determined.
*/
- enyo.findAndInstance = function (property, fn) {
+ enyo.findAndInstance = function (property, fn, context) {
var ctor;
var inst;
var path;
@@ -258,7 +258,7 @@
path = enyo.getPath.call(this, property);
// if there is nothing at the given property fast-path out
// and return undefined everything
- if (!path) return fn();
+ if (!path) return fn.call(context || this);
// if the path is a string (as in most cases) go ahead and
// attempt to get the kind definition or instance at the
// given path
@@ -287,7 +287,7 @@
// if we do have an instance assign it to the base object
if (exists(inst)) this[property] = inst;
// now use the calback and pass it the correct parameters
- return fn(ctor, inst);
+ return fn.call(context || this, ctor, inst);
};
//*@public
View
16 tools/test/core/tests/InheritanceSanityTest.js
@@ -0,0 +1,16 @@
+enyo.kind({
+ name: "InheritanceSanityTest",
+ kind: enyo.TestSuite,
+ testObject: function () {
+ this.finish(!(enyo.Object && enyo.Object instanceof Object));
+ },
+ testComponent: function () {
+ this.finish(!(enyo.Component && enyo.Component.prototype instanceof enyo.Object));
+ },
+ testUiComponent: function () {
+ this.finish(!(enyo.UiComponent && enyo.UiComponent.prototype instanceof enyo.Object));
+ },
+ testControl: function () {
+ this.finish(!(enyo.Control && enyo.Control.prototype instanceof enyo.Object));
+ }
+});
View
3  tools/test/core/tests/package.js
@@ -14,5 +14,6 @@ enyo.depends(
"PathResolverTest.js",
"ViewportPositioningTest.js",
"BindingTest.js",
- "ObjectControllerTest.js"
+ "ObjectControllerTest.js",
+ "InheritanceSanityTest.js"
);
Something went wrong with that request. Please try again.