-
Notifications
You must be signed in to change notification settings - Fork 329
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from rymohr/bind-store-methods
Automatically bind store methods
- Loading branch information
Showing
7 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = function(store, definition) { | ||
for (var name in definition) { | ||
var property = definition[name]; | ||
|
||
if (typeof property !== 'function' || !definition.hasOwnProperty(name)) { | ||
continue; | ||
} | ||
|
||
store[name] = property.bind(store); | ||
} | ||
|
||
return store; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// From https://github.com/facebook/react/blob/master/src/test/phantomjs-shims.js | ||
(function() { | ||
|
||
var Ap = Array.prototype; | ||
var slice = Ap.slice; | ||
var Fp = Function.prototype; | ||
|
||
if (!Fp.bind) { | ||
// PhantomJS doesn't support Function.prototype.bind natively, so | ||
// polyfill it whenever this module is required. | ||
Fp.bind = function(context) { | ||
var func = this; | ||
var args = slice.call(arguments, 1); | ||
|
||
function bound() { | ||
var invokedAsConstructor = func.prototype && (this instanceof func); | ||
return func.apply( | ||
// Ignore the context parameter when invoking the bound function | ||
// as a constructor. Note that this includes not only constructor | ||
// invocations using the new keyword but also calls to base class | ||
// constructors such as BaseClass.call(this, ...) or super(...). | ||
!invokedAsConstructor && context || this, | ||
args.concat(slice.call(arguments)) | ||
); | ||
} | ||
|
||
// The bound function must share the .prototype of the unbound | ||
// function so that any object created by one constructor will count | ||
// as an instance of both constructors. | ||
bound.prototype = func.prototype; | ||
|
||
return bound; | ||
}; | ||
} | ||
|
||
})(); |