C#, unfortunately, still does not have convenient ways of creating immutable classes with a convenient copy-and-update mechanism, deep equality semantics, and a sensible GetHashCode
implementation. (And this was cut from C#= 7. 😢) By representing our state with structs, our action handlers can be written conveniently as
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
/** Used by Flavor to mark a type in a readable way. */ | |
export interface Flavoring<FlavorT> { | |
_type?: FlavorT; | |
} | |
/** Create a "flavored" version of a type. TypeScript will disallow mixing flavors, but will allow unflavored values of that type to be passed in where a flavored version is expected. This is a less restrictive form of branding. */ | |
export type Flavor<T, FlavorT> = T & Flavoring<FlavorT>; | |
/** Used by Brand to mark a type in a readable way. */ | |
export interface Branding<BrandT> { | |
_type: BrandT; |
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
/** An empty type which "brands" a value as having been checked for validity */ | |
enum IsValidBrand {} | |
/** A `Valid<T>` is just a T that the type system knows is valid. */ | |
export type Valid<T> = T & IsValidBrand; | |
/** This is some arbitrary example type which we want to validate. */ | |
interface Model { nonEmptyArray: number[] } | |
/** A predicate to check that a model is valid. The return type tells TypeScript that this proves the argument is valid. */ |
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
public delegate TResult RefFunc<TState, TResult>(ref TState current); | |
public delegate void RefAction<TState>(ref TState current); | |
public delegate void RefAction<TState, TEvent>(ref TState state, TEvent action); | |
namespace Framework | |
{ | |
public static class RefPublishStrategies | |
{ |
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
public static class ReactiveProperty | |
{ | |
public static ReactiveProperty<T> Create<T>(IObservable<T> observable) => new ReactiveProperty<T>(observable); | |
} | |
public class ReactiveProperty<T> : INotifyPropertyChanged, IDisposable | |
{ | |
private readonly IDisposable _subscription; | |
private Exception _exception; | |
private T _value; |
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
var myDictionary = new Dictionary<string,object> {{"bar", 1}}; | |
var cmd = connection.CreateCommandWithNamedParameters("select * from table where foo = ?bar", myDictionary); | |
var reader = cmd.ExecuteReader(); |
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
class Context | |
def initialize() | |
@cache = {} | |
end | |
def [](klass) | |
if @cache.has_key?(klass) | |
@cache[klass] | |
else |
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
$(domNode).waypoint(function() { | |
initializeChart(domNode); | |
}, {offset: "100%", triggerOnce: true}); |
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
initializeChart(domNode); |
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
<script id="messages-template" type="text/html"> | |
<ul class="messages"> | |
<li><span class="text"> </span></li> | |
</ul> | |
</script> |
NewerOlder