Skip to content

Commit

Permalink
Merge pull request #43 from foretagsplatsen/allConcreteSubclasses
Browse files Browse the repository at this point in the history
Add object.allConcreteSubclasses
  • Loading branch information
DamienCassou authored Mar 17, 2017
2 parents 63d7174 + b0ce1c4 commit 60e1337
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 1 deletion.
18 changes: 18 additions & 0 deletions dist/klassified.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,23 @@ define('object',[], function() {
return allSubclasses;
};

/**
* Return all concrete subclasses.
*/
object.allConcreteSubclasses = function() {
var allConcreteSubclasses = this.subclasses.filter(function(klass) {
return !klass.isAbstract;
});

this.subclasses.forEach(function(klass) {
klass.allConcreteSubclasses().forEach(function(subclass) {
allConcreteSubclasses.push(subclass);
});
});

return allConcreteSubclasses;
};

object.subclassResponsibility = subclassResponsibility;

/**
Expand Down Expand Up @@ -676,6 +693,7 @@ define('object',[], function() {
that.singletonSubclass = object.singletonSubclass;
that.abstractSubclass = object.abstractSubclass;
that.allSubclasses = object.allSubclasses;
that.allConcreteSubclasses = object.allConcreteSubclasses;
that.subclassResponsibility = subclassResponsibility;
that.extend = object.extend;
that.extensions = [];
Expand Down
2 changes: 1 addition & 1 deletion dist/klassified.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions src/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,23 @@ define([], function() {
return allSubclasses;
};

/**
* Return all concrete subclasses.
*/
object.allConcreteSubclasses = function() {
var allConcreteSubclasses = this.subclasses.filter(function(klass) {
return !klass.isAbstract;
});

this.subclasses.forEach(function(klass) {
klass.allConcreteSubclasses().forEach(function(subclass) {
allConcreteSubclasses.push(subclass);
});
});

return allConcreteSubclasses;
};

object.subclassResponsibility = subclassResponsibility;

/**
Expand Down Expand Up @@ -236,6 +253,7 @@ define([], function() {
that.singletonSubclass = object.singletonSubclass;
that.abstractSubclass = object.abstractSubclass;
that.allSubclasses = object.allSubclasses;
that.allConcreteSubclasses = object.allConcreteSubclasses;
that.subclassResponsibility = subclassResponsibility;
that.extend = object.extend;
that.extensions = [];
Expand Down
Loading

0 comments on commit 60e1337

Please sign in to comment.