Skip to content

Commit

Permalink
New release: 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jcbrand committed Nov 5, 2017
1 parent 4677f75 commit 51ef27b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 24 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## 1.0.1 (Unreleased)
## 1.0.1 (2017-11-05)

- Ensure that `plugged` obj is also available in overriden constructors
- Plugins now can have an `enabled` attribute (either a method or a property)
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ BABEL-NODE ?= ./node_modules/.bin/babel-node
FAUCET ?= ./node_modules/.bin/faucet
BROWSER-RUN ?= ./node_modules/.bin/browser-run
BROWSERIFY ?= ./node_modules/.bin/browserify
SED ?= sed

all: stamp-npm

Expand Down Expand Up @@ -51,7 +52,7 @@ dist: lodash

.PHONY: release
release:
sed -i s/\"version\":\ \"[0-9]\.[0-9]\.[0-9]\"/\"version\":\ \"$(VERSION)\"/ package.json
sed -i "s/(Unreleased)/(`date +%Y-%m-%d`)/" CHANGES.md
$(SED) -ri s/\"version\":\ \"[0-9]\+\.[0-9]\+\.[0-9]\+\"/\"version\":\ \"$(VERSION)\"/ package.json
$(SED) -i "s/(Unreleased)/(`date +%Y-%m-%d`)/" CHANGES.md
make docs
make dist
54 changes: 33 additions & 21 deletions docs/pluggable.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,20 @@ <h1>pluggable.js</h1>

</div>

<div class="content"><div class='highlight'><pre> wrappedOverride: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">key, value, super_method</span>) </span>{
<div class="content"><div class='highlight'><pre> wrappedOverride: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">key, value, super_method, default_super</span>) </span>{
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> super_method === <span class="hljs-string">"function"</span>) {
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> <span class="hljs-keyword">this</span>.__super__ === <span class="hljs-string">"undefined"</span>) {
<span class="hljs-comment">/* We're not on the context of the plugged object.
* This can happen when the overridden method is called via
* an event handler. In this case, we simply tack on the
* __super__ obj.
*/</span>
<span class="hljs-keyword">this</span>.__super__ = {};
* This can happen when the overridden method is called via
* an event handler or when it's a constructor.
*
* In this case, we simply tack on the __super__ obj.
*/</span>
<span class="hljs-keyword">this</span>.__super__ = default_super;
}
<span class="hljs-keyword">this</span>.__super__[key] = super_method.bind(<span class="hljs-keyword">this</span>);
}
<span class="hljs-keyword">return</span> value.apply(<span class="hljs-keyword">this</span>, _.drop(<span class="hljs-built_in">arguments</span>, <span class="hljs-number">3</span>));
<span class="hljs-keyword">return</span> value.apply(<span class="hljs-keyword">this</span>, _.drop(<span class="hljs-built_in">arguments</span>, <span class="hljs-number">4</span>));
},</pre></div></div>

</li>
Expand Down Expand Up @@ -164,16 +165,19 @@ <h1>pluggable.js</h1>
<div class="content"><div class='highlight'><pre> _overrideAttribute: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">key, plugin</span>) </span>{
<span class="hljs-keyword">let</span> value = plugin.overrides[key];
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> value === <span class="hljs-string">"function"</span>) {
<span class="hljs-keyword">let</span> default_super = {};
default_super[<span class="hljs-keyword">this</span>.name] = <span class="hljs-keyword">this</span>.plugged;

<span class="hljs-keyword">let</span> wrapped_function = _.partial(
<span class="hljs-keyword">this</span>.wrappedOverride, key, value, <span class="hljs-keyword">this</span>.plugged[key]
<span class="hljs-keyword">this</span>.wrappedOverride, key, value, <span class="hljs-keyword">this</span>.plugged[key], default_super
);
<span class="hljs-keyword">this</span>.plugged[key] = wrapped_function;
} <span class="hljs-keyword">else</span> {
<span class="hljs-keyword">this</span>.plugged[key] = value;
}
},

_extendObject: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">obj, attributes</span>) </span>{
<span class="hljs-attr">_extendObject</span>: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">obj, attributes</span>) </span>{
<span class="hljs-keyword">if</span> (!obj.prototype.__super__) {
obj.prototype.__super__ = {};
obj.prototype.__super__[<span class="hljs-keyword">this</span>.name] = <span class="hljs-keyword">this</span>.plugged;
Expand Down Expand Up @@ -201,8 +205,11 @@ <h1>pluggable.js</h1>

</div>

<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">let</span> wrapped_function = _.partial(
that.wrappedOverride, key, value, obj.prototype[key]
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">let</span> default_super = {};
default_super[that.name] = that.plugged;

<span class="hljs-keyword">let</span> wrapped_function = _.partial(
that.wrappedOverride, key, value, obj.prototype[key], default_super
);
obj.prototype[key] = wrapped_function;
} <span class="hljs-keyword">else</span> {
Expand Down Expand Up @@ -251,7 +258,7 @@ <h1>pluggable.js</h1>
});
},

throwUndefinedDependencyError: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">msg</span>) </span>{
<span class="hljs-attr">throwUndefinedDependencyError</span>: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">msg</span>) </span>{
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">this</span>.plugged.strict_plugin_dependencies) {
<span class="hljs-keyword">throw</span> msg;
} <span class="hljs-keyword">else</span> {
Expand Down Expand Up @@ -302,7 +309,7 @@ <h1>pluggable.js</h1>
<a class="pilcrow" href="#section-10">&#182;</a>
</div>
<p><code>initializePlugin</code> applies the overrides (if any) defined on all
the registered plugins and then calls the initialize method for each plugin.</p>
the registered plugins and then calls the initialize method of the plugin</p>

</div>

Expand All @@ -317,15 +324,20 @@ <h1>pluggable.js</h1>
*/</span>
<span class="hljs-keyword">return</span>;
}
_.extend(plugin, <span class="hljs-keyword">this</span>.properties);
<span class="hljs-keyword">if</span> (plugin.optional_dependencies) {
<span class="hljs-keyword">this</span>.loadOptionalDependencies(plugin);
}
<span class="hljs-keyword">this</span>.applyOverrides(plugin);
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> plugin.initialize === <span class="hljs-string">"function"</span>) {
plugin.initialize.bind(plugin)(<span class="hljs-keyword">this</span>);
<span class="hljs-keyword">if</span> (_.isBoolean(plugin.enabled) &amp;&amp; plugin.enabled ||
_.isFunction(plugin.enabled) &amp;&amp; plugin.enabled(<span class="hljs-keyword">this</span>.plugged) ||
_.isNil(plugin.enabled)) {

_.extend(plugin, <span class="hljs-keyword">this</span>.properties);
<span class="hljs-keyword">if</span> (plugin.optional_dependencies) {
<span class="hljs-keyword">this</span>.loadOptionalDependencies(plugin);
}
<span class="hljs-keyword">this</span>.applyOverrides(plugin);
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> plugin.initialize === <span class="hljs-string">"function"</span>) {
plugin.initialize.bind(plugin)(<span class="hljs-keyword">this</span>);
}
<span class="hljs-keyword">this</span>.initialized_plugins.push(plugin.__name__);
}
<span class="hljs-keyword">this</span>.initialized_plugins.push(plugin.__name__);
},</pre></div></div>

</li>
Expand Down

0 comments on commit 51ef27b

Please sign in to comment.