Permalink
Browse files

Adding feature.HasMixins which allows a kind to specify which mixins …

…it wants to include in its recipe.
  • Loading branch information...
madnificent committed Jul 4, 2012
1 parent 0d4f473 commit 8b9185277b62ac987103dde99e60628b008264f4
Showing with 75 additions and 1 deletion.
  1. +23 −0 contrib/HasMixins/HasMixins.js
  2. +47 −0 contrib/HasMixins/example.js
  3. +3 −0 contrib/HasMixins/package.js
  4. +2 −1 contrib/package.js
@@ -0,0 +1,23 @@
+/**
+ feature.HasMixins can be used to include various mixins in your kind. Your kind's recipe will be exended by the various mixins which you supply to it.
+
+ if you are defining a feature and want to let it extend the kind with a set of mixins, you should olok at feature.IsMixin.
+ */
+enyo.kind( {
+ name : "feature.HasMixins",
+ kind : feature.Feature,
+ //* @public
+ /**
+ Holds the mixins with which the recipe will be overwritten.
+ */
+ mixins : [],
+ //* @protected
+ atKind : function( user ) {
+ var feature = this;
+
+ enyo.map( feature.mixins ,
+ enyo.bind(this,function(mixin){
+ enyo.mixin( user, mixin );
+ } ) );
+ }
+} );
@@ -0,0 +1,47 @@
+/**
+ This is a basic example of enyo.hasMixins.
+
+ The example includes a mixin in feature.HasMixin.example which adds support for warning output. The output can be configured based on the mixins [ simpleWarningFormatMixin , informedWarningFormatMixin , responsibleWarningFormatMixin , slangWarningFormatMixin ].
+*/
+
+var warningsMixin = {
+ warnDeveloper : function( message ) {
+ console.log( this.buildWarning( message ) );
+ },
+ warnUser : function( message ) {
+ alert( this.buildWarning( message ) );
+ }
+};
+
+
+var simpleWarningFormatMixin = {
+ buildWarning : function( message ){
+ return message;
+ }
+}
+
+var informedWarningFormatMixin = {
+ buildWarning : function( message ){
+ return "Warning: " + message;
+ }
+}
+
+var responsibleWarningFormatMixin = {
+ buildWarning : function( message ){
+ return "Warning from " + this + ": " + message;
+ }
+}
+
+var slangWarningFormatMixin = {
+ buildWarning : function( message ){
+ return "Yo dawg, " + this + " says word. " + message;
+ }
+}
+
+enyo.kind({
+ name : "feature.HasMixin.example",
+ kind : enyo.Control,
+ features : [ { kind : feature.HasMixins,
+ mixins : [ warningsMixin , responsibleWarningFormatMixin ]
+ } ]
+});
@@ -0,0 +1,3 @@
+enyo.depends(
+ "HasMixins.js"
+);
View
@@ -1,4 +1,5 @@
enyo.depends(
"PublishComponent",
- "IsMixin"
+ "IsMixin",
+ "HasMixins"
);

0 comments on commit 8b91852

Please sign in to comment.