// A is a phantom type that ties an event instance...
class Event<A> {}
// ...to its handler
type Handler<A> = (a: A, ...rest: Array<void>) => void;
declare class EventEmitter {
on<A, F: Handler<A>>(event: Event<A>, handler: F): void;
emit<A>(event: Event<A>, a: A): void;
}
All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.
Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.
elem.offsetLeft
,elem.offsetTop
,elem.offsetWidth
,elem.offsetHeight
,elem.offsetParent
React introduced shallow rendering in 0.13. This is an excellent feature that I wish was included earlier in React. It aims to solve the problem of unit testing components without going through a real, or jsdom mocked, DOM. I couldn't find any info online about what lifecycle events it actually fires. So I did some testing of my own. To reproduce, put component.js
and test.js
into a folder and run node test.js
.
TLDR; shallow rendering only invokes the following lifecycle hooks (in order):
getDefaultProps
getInitialState
componentWillMount
stops here until re-rendercomponentWillReceiveProps
shouldComponentUpdate
componentWillUpdate
I'm not suggesting drastic action. I don't want to break backwards compatibility. I simply want to make the class
feature more usable to a broader cross section of the community. I believe there is some low-hanging fruit that can be harvested to that end.
Imagine AutoMaker contained class Car
, but the author wants to take advantage of prototypes to enable factory polymorphism in order to dynamically swap out implementation.
Stampit does something similar to this in order to supply information needed to inherit from composable factory functions, known as stamps.
This isn't the only way to achieve this, but it is a convenient way which is compatible with .call()
, .apply()
, and .bind()
.
const CANCEL = Symbol(); | |
class CancellationToken { | |
constructor() { | |
this.cancelled = false; | |
} | |
throwIfCancelled() { | |
if (this.isCancelled()) { |
#!/usr/bin/env ruby | |
# use https://github.com/libgit2/rugged | |
require 'rugged' | |
# all dirs under the current path with git repos | |
repo_dirs = Dir.glob("**/.git", File::FNM_DOTMATCH) | |
# init rugged objects | |
repos = repo_dirs.map do |repo_path| |
#!/usr/bin/env python | |
#-*- coding: utf-8 -*- | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== | |
<img width="1" height="1" title="" alt="" src="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" /> |