Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Remixin is the aspect-oriented mixin library developed and in use at SoundCloud. It is inspired by Twitter's advice.js and Joose.
For an introduction about why you'd want to use a mixin library, Angus Croll and Dan Webb from Twitter gave a good talk about the concept and Angus blogged on the subject.
Install the package via npm:
npm install remixin
And then import it:
import { Mixin } from 'remixin';
Alternatively, download a browser-ready version from the unpkg CDN:
<script src="https://unpkg.com/underscore"></script> <!-- creates window._ -->
<script src="https://unpkg.com/remixin"></script> <!-- creates window.remixin -->
(Underscore.js is a dependency and needs to be included first.)
mixin = new Mixin(modifiers)
mixin.applyTo(object)
mixin.applyTo(object, options)
curried = mixin.withOptions(options)
combined = new Mixin(mixin1, [mixin2, ...], modifiers)
When defining a mixin, there are several key words to define method modifiers:
before
: {Object.<String,Function>}
after
: {Object.<String,Function>}
before
, this has the same signature, but can not modify the return value of the function.around
: {Object.<String,Function>}
requires
: {Array.<String>}
requirePrototype
: {Object}
override
: {Object.<String,*>}
defaults
: {Object.<String,*>}
merge
: {Object.<String,Array|Object|String}
_.extend({}, mixin.obj, target.obj)
.All other keys are copied onto the target object unless that key already exists. If overriding these keys is desired,
then it should be defined in the override
block. If a default implementation is desired, then it should be defined in
the defaults
block.
Incorrect use of these modifiers will throw an error if Mixin.debug
is set to true
. For example, if a field declared in requires
is not found, or if a before
is applied on a non-function. By default, Mixin.debug
is false
.
applyTo
If custom code is required for your mixin, then defining a key named applyTo
allows a custom method to be executed
when the mixin is applied. This method is passed two arguments: the target object and any options defined by the
calling code:
zoomable = new Mixin({
applyTo(obj, options) {
this.extend(obj, {
zoom() {
this.width *= options.zoomRatio;
this.height *= options.zoomRatio;
}
});
}
});
zoomable.applyTo(MyCanvasObject.prototype, { zoomRatio: 2 });
All of the standard modifier names (eg: after, around, before) are available in the context, as well as extend
to add
new properties.
Taking the example from above, sometimes it's more convenient to have the options curried into the mixin already. For
this, use .withOptions
which will return a new mixin with those options stored. For example:
var standardDPI = zoomable.withOptions({ zoomRatio: 1});
var highDPI = zoomable.withOptions({ zoomRatio: 2 });
Sometimes, one mixin will necessitate the target object also having another mixin. For example, you might have a mixin which gives a View the behaviour of a drop-down menu. Drop-down menus have some shared behaviour with other overlays, such as modal dialogues. These can be combined into a single mixin, to hide the implementation from the class which requires the combined behaviour:
overlay = new Mixin({
merge: {
events: {
'click .closeButton': 'onCloseClick'
}
},
show() { ... },
hide() { ... },
onCloseClick() {
this.hide();
}
});
dropDownMenu = new Mixin(overlay, {
after: {
onCloseClick() {
this.parentButton.focus();
}
}
});
ProfileButton = View.extend({ ... });
dropDownMenu.applyTo(ProfileButton.prototype);
Any number of mixins can be combined into one:
megaMixin = new Mixin(mixin1, mixin2, mixin3, mixin4, {});
To build the source:
make
To run the tests:
make test
To see a coverage report:
make coverage
2.0.0 (2019-08-06)
__DEBUG__
global variable (that is used to toggle some debugging behavior) with a debug
static property.FAQs
Aspect-oriented, mixin library
The npm package remixin receives a total of 1 weekly downloads. As such, remixin popularity was classified as not popular.
We found that remixin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.