Skip to content

Instantly share code, notes, and snippets.

View mweststrate's full-sized avatar
💭
I may be slow to respond.

Michel Weststrate mweststrate

💭
I may be slow to respond.
View GitHub Profile
var CartView = React.createClass({
render: function() {
function renderEntry(entry) {
return (<CartEntryView entry={entry} cart={this.props.cart} key={entry.id} />);
}
return (<div>
<ul id="cart">{this.props.cart.entries.map(renderEntry)}</ul>
<div><b>Total: <span id="total">{this.props.cart.total}</span></b></div>
</div>)
}
@mweststrate
mweststrate / gist:0d6edd6645845a9aca47
Created July 15, 2015 19:52
pure rendering over time using MOBservable - output
<div>Seats left: 500<hr/>Attendees: </div>
<div>Seats left: 499<hr/>Attendees: Michel</div>
<div>Seats left: 498<hr/>Attendees: Michel, You?</div>
<div>Seats left: 498<hr/>Attendees: @mweststrate, You?</div>
<div>Seats left: 748<hr/>Attendees: @mweststrate, You?</div>
@mweststrate
mweststrate / gist:3103734
Created July 13, 2012 08:49
xpath example 4
private String implementation4(String name, Category category, Long offset) throws CoreException
{
StringBuilder b = new StringBuilder();
//create the xpath
XPath<Product> xpath = XPath.create(getContext(), Product.class)
.subconstraint( Product.MemberNames.Product_ProductState , ProductState.entityName )
.eq( ProductState.MemberNames.Published , true )
.or()
.eq( ProductState.MemberNames.PublishAnyway , true )
@mweststrate
mweststrate / xpath2.java
Created July 13, 2012 08:34
xpath example java 2
//...
//create the xpath
String xpath = String.format("//%s[%s/%s[%s = true() or %s = true()]][%s = '%s'][%s = '%s']",
Product.entityName,
Product.MemberNames.Product_ProductState, ProductState.entityName,
ProductState.MemberNames.Published, ProductState.MemberNames.PublishAnyway,
Product.MemberNames.Product_Category, category.getGUID(),
Product.MemberNames.Name, name
);
//...
@mweststrate
mweststrate / transaction.jsx
Created December 21, 2015 18:53
transaction example
transaction(() => {
michel.firstName = "Mich";
michel.lastName = "W.";
});
@mweststrate
mweststrate / autorun.js
Last active February 26, 2016 17:59
Object.observe is dead. Long live Mobservable.observe
// JSBin: http://jsbin.com/xoyehi/edit?js,console
import {observable, autorun} from "mobx";
const todos = observable([{
title: "Find napkin",
completed: false
}]);
autorun(() =>
console.log(todos
@mweststrate
mweststrate / mobx-repl.sh
Last active February 26, 2016 18:03
install and run MobX in REPL
npm init -y && npm install mobx --save && node -e "global.mobx=require('mobx'); require('repl').start({ useGlobal: true});"
@mweststrate
mweststrate / gist:5c1a29ee80832f28f3be
Last active February 26, 2016 18:04
data model using mobservables
function Article(name, price) {
mobx.extendObservable(this, {
name: name,
price: price
});
}
function ShoppingCartEntry(article) {
mobx.extendObservable(this, {
article: article,
var CartEntryView = mobxReact.observer(React.createClass({
render: function() {
return (<li>
// etc...
@mweststrate
mweststrate / typeswitcher.ts
Created April 14, 2016 14:01
(TypeScript) typeswitcher, like switch, but with constructor based cases and expressions with inferred types
/**
* Usage:
typeSwitch(someInstance, defaultvalue)
.when(MyClass, i => result)
.when(OtherClass, i => otherResult)
.get()
In the expressions, the type of the 'i' param should be inferred correctly, see the attribute default value checks
*/
export function typeSwitch<T, R>(instance: T, defaultValue?: R): TypeSwitcher<T, R> {