Skip to content

Instantly share code, notes, and snippets.

View mikaelbr's full-sized avatar

Mikael Brevik mikaelbr

View GitHub Profile
var immstruct = require('immstruct');
var component = require('omniscient');
var data = immstruct({ a: {b: { c: { text: 'hello', foo: { bar: 'world' }}}});
var AnotherComp = component((cursor) => /* ... */);
var TextComp = component((cursor) => (
<div>
<p>{cursor.get('text')}</p>
gulp.task('gitmodifiedfiles', function(cb) {
var files = gulp.src(phpFiles)
.pipe(gitmodified('modified'));
var modifiedFiles = [];
files.on('data', function (file) {
modifiedFiles.push(file.path);
}).on('end', function () {
phplint(modifiedFiles, { limit : 10 }, cb);
});
@mikaelbr
mikaelbr / update-structure.js
Created April 1, 2015 17:50
Example multiple changes with only one emit and without `withMutations`
const structure = immstruct({
blog: {
name: 'My Blog',
articles: [],
articleForm: {
title: 'Hello',
body: 'foo'
}, // uncommitted form
errorState: {
errors: { message: 'Foo Error'}, // form errors
(ns fizz.core)
(defn is-fizz? [x] (zero? (mod x 3)))
(defn is-buzz? [x] (zero? (mod x 5)))
(defn is-fizzbuzz? [x]
((every-pred is-fizz? is-buzz?) x))
(defn to-fizzbuzz [x]
(cond
(is-fizzbuzz? x) "FizzBuzz"
var data = immstruct({
foo: 'message',
bar: 'some value'
});
// Create a cursor to the top level
var cursor = data.cursor();
// See that foo on current structure is infact "message"
console.log(data.current.toJS().foo); //=> message
// See that the data the cursor is pointing at is also "message". All is good
// Or something like this using event object
console.clear();
var RadioButtonList = React.createClass({
propTypes: {
handleSelect: React.PropTypes.func.isRequired
},
value: function () {
// get selected element and return it
// using React.findDOMNode(this).querySelector(":checked")
@mikaelbr
mikaelbr / changelog.md
Last active August 29, 2015 14:23
Immstruct 2.0.0 changelog

Version 2.0.0 with improved references. In addition to much more powerful references, there are also breaking changes with the passed event arguments and how you access the list of instances from a Immstruct instance.

Breaking Changes

  • Removes instances property from API. No longer a property .instances on the Immstruct instance which allow you to access the list of instances. It's now a method instance which allow you to get either the complete list, if no arguments, or a specific instance given by key as first argument.
var immstruct = require('immstruct');

immstruct('foo', {});
immstruct.instance(); // =&gt; { 'foo': Immutable.Map }
// Just functions, but a simple tool to guide the organization of
// these functions. Also allows for the ability to dynamically
// change the collection of these functions as they are passed
// down as props in components.
var structure = immstruct({ foo: 4 });
function square (cursor) {
return cursor.update((input) => input * input);
}
type Person = {
age: int
id: string
name: string
}
type IdName = {
id: string
name: string
// Function to exec bundle and create dist files.
function buildJavascript (stream) {
return stream.bundle()
.pipe(source(path.basename(ep)))
.pipe(gulp.dest('where/dist/is/'));
}
// Setup for browserify
var bundleStream = browserify()