Skip to content

Instantly share code, notes, and snippets.

@itrelease
itrelease / Stateful.js
Last active August 29, 2015 14:19 — forked from gaearon/Stateful.js
import React, { Component } from 'react';
// Usage:
//
// @Stateful({
// initialize(props) {
// return {
// count: 0
// };
// },
export default {
getInitialState() {
const data = {};
this.subscribe(this.props, this.context, (key, value) => {
data[key] = value;
});
this.unsubscribe();
return { data };
{
"root": [
"news/2015/01/21/zhopik",
"news/2015/01/21/another-test",
"feature/2015/01/21/ficher-s-bez-kartin",
"news/2015/01/19/test-memchikov",
"cards/kak-ustroen-zakon-pro-inostrantsev-v-smi",
"galleries/2015/01/16/charlie-hebdo",
"galleries/2014/11/21/poves-moy-brauzer",
"news/2014/11/18/novost-na-proverku-reklamy-s-otnositelnym-urolom",
var path = require('path');
var express = require('express');
var nunjucks = require('nunjucks');
var logger = require('bunyan').createLogger({ name: 'mdz:web' });
module.exports = function (redisClient, config, development) {
'use strict';
var HOST = process.env.FRONT_HOST || 'meduza.io';
var DEST_ROOT = development ? config.DEV_DEST_ROOT : config.DIST_DEST_ROOT;
'use strict';
var React = require('react'),
_ = require('underscore'),
DelayActionMixin = require('../mixins/DelayActionMixin'),
ClassNameMixin = require('../mixins/ClassNameMixin'),
PureRenderMixin = require('../mixins/PureRenderMixin');
var PALETTE = [
"FECDD3","FD99A5","FC677A","FB334C","F6001F","C80019","970013","64000C",
'use strict';
var React = require('react'),
createStoreMixin = require('../mixins/createStoreMixin'),
ClassNameMixin = require('../mixins/ClassNameMixin'),
PlayerActionCreators = require('../actions/PlayerActionCreators'),
PlayerStore = require('../stores/PlayerStore'),
StampImageMixin = require('../mixins/StampImageMixin'),
PureRenderMixin = require('../mixins/PureRenderMixin'),
BlurredBackground = require('../atoms/BlurredBackground'),
// Usage example:
//
// willTransitionTo(transition, params) {
// transition.wait(
// observeStore(
// DraftStore,
// s => s.isLoaded()
// ).then(() => {
// if (DraftStore.isMissingTitle()) {
// transition.redirect('composeDraft', params);

Virtual DOM and diffing algorithm

There was a [great article][1] about how react implements it's virtual DOM. There are some really interesting ideas in there but they are deeply buried in the implementation of the React framework.

However, it's possible to implement just the virtual DOM and diff algorithm on it's own as a set of independent modules.

(function() {
// Do not use this library. This is just a fun example to prove a
// point.
var Bloop = window.Bloop = {};
var mountId = 0;
function newMountId() {
return mountId++;
}
/**
* Automatic Reference Counting (ARC) Garbage Collection technique.
*
* This diff describes Reference counting GC technique.
* See also previous lesson on Mark and Sweep GC:
* https://gist.github.com/4391763
*
* Covered topics:
*
* 1. Reference value in ECMAScript (JS specific)