extends-mixin
The purpose of this package is to provide a function for reducing a collection of mixins into a single mixin that applies each of the mixins. Let's take an example:
Lets assume we have a Person
class with a name
field that we want to augment
to include accessors for accessing a person's first and last name.
{thisname = name;}const john = 'John Doe';assert;
We can create a mixin to get the first name like so:
const canGetFirstName ={return thisname;};const PersonWithFirstName = ;const john = 'John Doe';assert;assert;
We can also create another mixin to get the last name like so:
const canGetLastName ={return thisname;};const PersonWithLastName = ;const john = 'John Doe';assert;assert;
If we want to combine the mixins, we would typically do something like this:
const PersonWithFirstAndLastName = ;const john = 'John Doe';assert;assert;assert;
While this appears ok for two mixins, it becomes difficult to read as the number of mixins increase. Consider the following:
const CustomPerson = ;
The purpose of this package is to make combining mixins easier by allowing you to do this:
const mix = ;const canGetAncestry =;const CustomPerson = ;
You can also pass each mixin as an argument if it is more convenient:
const mix = ;const canGetAncestry =;const CustomPerson = ;
If your mixin list happens to be empty, the identity function is returned:
const mix = ;const identity = ;const JustAPerson = ;const john = 'John Doe';assert;
Because this package reduces many mixins to a single mixin, grouping mixins is easy:
const mix = ;const canGetFirstAndLastName = ;const canGetChildrenAndSiblings = ;const canGetAncestry = ;const CustomPerson = ;
As a convenience, a function is provided for loading all mixins within a
directory. Nested directories are required as normal. Only files with .js
extensions are accepted and index.js
is ignored. A typical index.js
would be the following:
moduleexports = __dirname;
Pull requests and bug reports are welcome, as always.