This post has moved to my personal blog: http://maximilianschmitt.me/posts/iojs-command-line-apps-nodejs/
(function (undefined) { | |
/** | |
* moment.easter | |
* Source: https://github.com/zaygraveyard/moment-easter | |
* License: MIT | |
*/ | |
moment.easter = function Easter20ops(year) { | |
var a = (year / 100 | 0) * 1483 - (year / 400 | 0) * 2225 + 2613; | |
var b = ((year % 19 * 3510 + (a / 25 | 0) * 319) / 330 | 0) % 29; | |
var c = 148 - b - ((year * 5 / 4 | 0) + a - b) % 7; |
function bound(object, key, descriptor) { | |
let boundMethodId = Symbol('bound-method-'+key); | |
let theMethod = descriptor.value; | |
delete descriptor.value; | |
delete descriptor.writable; | |
descriptor.get = function() { | |
//Memoize it per instance so we can remove listeners | |
return this[boundMethodId] || (this[boundMethodId] = theMethod.bind(this)); | |
}; |
React now supports the use of ES6 classes as an alternative to React.createClass()
.
React's concept of Mixins, however, doesn't have a corollary when using ES6 classes. This left the community without an established pattern for code that both handles cross-cutting concerns and requires access to Component Life Cycle Methods.
In this gist, @sebmarkbage proposed an alternative pattern to React mixins: decorate components with a wrapping "higher order" component that handles whatever lifecycle methods it needs to and then invokes the wrapped component in its render()
method, passing through props
.
While a viable solution, this has a few drawbacks:
- There's no way for the child component to override functionality defined on the higher order component.
// https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/operators/retrywhen.md | |
function exponentialBackOffScheduler(options) { | |
return function(errors) { | |
return errors.scan(options, function(currentOptions, err) { | |
if (currentOptions.maxRetries <= 0) { | |
throw err; | |
} | |
return { | |
maxRetries: currentOptions.maxRetries - 1, |
// ------------ | |
// counterStore.js | |
// ------------ | |
import { | |
INCREMENT_COUNTER, | |
DECREMENT_COUNTER | |
} from '../constants/ActionTypes'; | |
const initialState = { counter: 0 }; |
cover(width = inherit, height = inherit, min-width = 100%, min-height = 100%) | |
// Chrome, Safari | |
@media screen and (-webkit-min-device-pixel-ratio: 0) | |
object-fit cover | |
height height | |
width width | |
// Firefox | |
@-moz-document url-prefix() | |
& | |
object-fit cover |
I would recommend @acdlite's redux-actions over the methods suggested in this Gist.
The methods below can break hot-reloading and don't support Promise-based actions.
Even though 'redux-actions' still uses constants, I've come to terms with the fact that constants can be good, especially in bigger projects. You can reduce boilerplate in different places, as described in the redux docs here: http://gaearon.github.io/redux/docs/recipes/ReducingBoilerplate.html