Skip to content

Instantly share code, notes, and snippets.

View SanderSpies's full-sized avatar
🐫
wasm

Sander SanderSpies

🐫
wasm
View GitHub Profile
@SanderSpies
SanderSpies / Example.js
Last active March 30, 2016 07:26
React pattern matching braindumb
const test = (props) => (
<div>
{match(props).with(
(String) => <div>Should work {props}</div>,
({bar = '1', test: {x = false}}) => <div>Super cool {bar}</div>,
({bar = '5', test: {y = true}}) => <div>Mega cool {test.y} {y}</div>,
([a = 3, {x = 4}, z]) =>
<nesting>
{match(z).with(
({bar = '5', test: {y = true}}) =>
let context = createGlobalContext null in
let script = createStringWithUTF8CString "(function(){return 'Hi OCaml, this is your friend JavaScriptCore.';})();" in
let valueref = evaluateScript context script null null 0 null in
let result = valueToString context valueref null in
let ocaml_str = toOCamlString result in (
print_string ocaml_str;
releaseString script;
releaseGlobalContext context;
releaseOCamlString ocaml_str);;
open ReactDOM
module MyComponent = struct
(* Component Properties *)
type props = {count: int}
(* Hey, state can be any type! *)
type state = string
(* Initializer *)
@SanderSpies
SanderSpies / gist:b3218e861e12ed6477eb
Created April 2, 2015 15:03
React Style Syntax with media query example
var ApplicationStyles = StyleSheet.create`
.normalStyle {
background-color: white;
font-size: 10pt;
padding: 1em;
margin: 10px;
}
.childStyle {
var foo = <div>
if (foo) {
<something>
for(var i = 0, l = 10; i < 10; i++) {
<a prop={i} />
}
</something>
}
"2222"
</div>;
@SanderSpies
SanderSpies / gist:dc4e2a5ca1f95b3d2b26
Last active August 29, 2015 14:14
Rough touch support idea for React Magician
/**
* @jsx React.DOM
*/
'use strict';
var React = require('react');
var Animation = require('react-magician');
class Foo extends React.Component {
@SanderSpies
SanderSpies / gist:0b2963e8e2d5eb2ca359
Last active August 29, 2015 14:14
React Animation prototyping
/**
* @jsx React.DOM
*/
'use strict';
var React = require('react');
var ReactAnimation = require('react-animation');
var Animation = ReactAnimation.Animation;
class Foo extends React.Component {

So this is my current solution for "fixing" the implicit nature of CSS. It basically replaces CSS selectors, classNames, etc. with the ability to directly reference to a style from JavaScript.

/**
 * @jsx React.DOM
 */
'use strict';

var React = require('react');
var ReactStyle = require('react-style');
'use strict';
var merge = require('../vendor/merge');
var TransitionMixin = {
transitionStart: function(opt) {
var self = this;
return new Promise(function(resolve) {
opt.transition = 'all ' + opt.duration + ' linear';
@SanderSpies
SanderSpies / gist:9ce7eec0e1c3394c7003
Last active August 29, 2015 14:05
CSS reset for react-style
var allInitial;
var testElement = document.createElement('div');
// Firefox
if ('all' in testElement.style) {
allInitial = {
all: 'initial'
};
}
else {
testElement.style.display = 'initial';