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
const magicByte = 0 | |
// Optimized to try and not have to re-allocate memory through Buffer.concat. | |
// We allocate 1k to begin with, hoping that fits the message | |
// and we don't have to relocate again. Otherwise, tough luck. | |
function toBuffer(value, type, schemaId, length = 1024) { | |
const buf = Buffer.allocUnsafe(length) // unsafe, might contain old / sensitive data | |
buf.writeInt8(magicByte) | |
buf.writeInt32BE(schemaId, 1) |
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 Immutable = require('immutable'), | |
_ = require('lodash'), | |
IMap = Immutable.Map, | |
IVector = Immutable.Vector; | |
var messagesData = [ | |
{ | |
id: 'm_1', | |
threadID: 't_1', | |
threadName: 'Jing and Bill', |
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
// Not tested, but the main gist of glueing ampersand state and react components together well. The actual mixin I use in production is slightly more eleborate (handling the stopping of listening and rebinding through the component's lifecycle), but the main idea is there. | |
var Events = require('backbone-events-standalone'), | |
React = require('react'), | |
State = require('ampersand-state'); | |
var PostModel = State.extend({ | |
props: { | |
title: 'string', | |
body: 'string' |
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 AmpersandState = require('ampersand-state'); | |
var AmpersandCollection = require('ampersand-collection'); | |
var PostA = AmpersandState.extend({}); | |
var PostB = AmpersandState.extend({}); | |
var Posts = AmpersandCollection.extend({ | |
model: function(attrs, options) { | |
if (1 === 1) { |
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 State = require('ampersand-state'), | |
_ = require('lodash'); | |
module.exports = function(childModels) { | |
if (!childModels) childModels = {}; | |
var props = {}; | |
_.each(childModels, function(def, name) { | |
props[name] = 'state'; |
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 AmpersandState = require('ampersand-state'); | |
var Smile = AmpersandState.extend({ | |
props: { | |
width: 'number' | |
} | |
}); | |
var Person = AmpersandState.extend({ | |
props: { |