A tiny (265 byte) utility to create state machine components using two pure functions.
The API is a single function that accepts 2 pure functions as arguments:
using System; | |
namespace DI | |
{ | |
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] | |
public class DependsOnInstancesAttribute : Attribute | |
{ | |
public DependsOnInstancesAttribute(params Type[] instanceTypes) | |
{ |
/** Usage: | |
* const MyView = unrecycle(props => { | |
* // this is normally a no-go and creates leaking styles, but it won't with unrecycle(): | |
* <input ref={ c => c && c.style.background='red' } /> | |
* }) | |
*/ | |
export default function unrecycle(Component) { | |
return function Unrecycle(props, context) { | |
this.componentWillUnmount = dontRecycle; | |
return Component.call(this, props, context); |
A tiny (265 byte) utility to create state machine components using two pure functions.
The API is a single function that accepts 2 pure functions as arguments:
import { h, Component } from 'preact'; | |
/** Creates a new store, which is a tiny evented state container. | |
* @example | |
* let store = createStore(); | |
* store.subscribe( state => console.log(state) ); | |
* store.setState({ a: 'b' }); // logs { a: 'b' } | |
* store.setState({ c: 'd' }); // logs { c: 'd' } | |
*/ |
I recently had several days of extremely frustrating experiences with service workers. Here are a few things I've since learned which would have made my life much easier but which isn't particularly obvious from most of the blog posts and videos I've seen.
I'll add to this list over time – suggested additions welcome in the comments or via twitter.com/rich_harris.
Chrome 51 has some pretty wild behaviour related to console.log
in service workers. Canary doesn't, and it has a load of really good service worker related stuff in devtools.
/* bling.js */ | |
window.$ = document.querySelector.bind(document); | |
window.$$ = document.querySelectorAll.bind(document); | |
Node.prototype.on = window.on = function(name, fn) { this.addEventListener(name, fn); }; | |
NodeList.prototype.__proto__ = Array.prototype; | |
NodeList.prototype.on = function(name, fn) { this.forEach((elem) => elem.on(name, fn)); }; |
import java.io.FileDescriptor; | |
import java.io.FileOutputStream; | |
import java.io.IOException; | |
import java.io.OutputStream; | |
import java.io.PrintStream; | |
public class HelloWorld{ | |
private static HelloWorld instance; | |
public static void main(String[] args){ | |
instantiateHelloWorldMainClassAndRun(); |