Skip to content

Instantly share code, notes, and snippets.

View mridgway's full-sized avatar

Michael Ridgway mridgway

View GitHub Profile
@mridgway
mridgway / poorMansDevTool.js
Last active April 6, 2017 01:07
Poor mans React dev tools
var hook = {
inject: (renderer) => {
var oldMountComponent = renderer.Reconciler.mountComponent,
oldPerformUpdateIfNecessary = renderer.Reconciler.performUpdateIfNecessary,
oldReceiveComponent = renderer.Reconciler.receiveComponent,
oldUnmountcomponent = renderer.Reconciler.unmountComponent;
renderer.Reconciler.mountComponent = function overrideMountComponent() {
hook.emit('mountComponent', Array.prototype.slice.call(arguments));
return oldMountComponent.apply(renderer.Reconciler, arguments);
@mridgway
mridgway / README.md
Last active February 22, 2016 22:57
Upcoming changes in MockActionContext that may affect your tests

Currently (fluxible@1.0.3) the MockActionContext executes actions in a synchronous manner, which differs from how the actions are executed with the real Fluxible action context. We have found that this introduces inconsistencies when testing nested actions (actions that call other actions) since the callbacks for the nested action will not be called in the correct order or at all. This means that some tests were not even executing the callbacks that contained the test assertions.

To fix this, we are unifying the MockActionContext and ActionContext implementation so that they are identical. This guarantees that the tests will be asserting against the real executeAction implementation.

While the changes should not impact most users, there are some cases where a unit test could be relying on the execution order of parallel actions which could be broken. I have tested against several of the largest codebases inside Yahoo to see how large the impact would be and

var createReducerStore = require('./createReducerStore');
var MessageStoreReducers = require('./reducers/MessageStoreReducers');
var MessageStore = createReducerStore('MessageStore', {
messages: {},
sortedByDate: []
}, {
'RECEIVE_MESSAGES': MessageStoreReducers.receiveMessages,
'OPEN_THREAD': MessageStoreReducers.openThread
}, {
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Fluxible = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
/**
* Copyright 2015, Yahoo Inc.
* Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
*/
'use strict';
var React = require('react/
/**
* Copyright 2014, Yahoo! Inc.
* Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
*/
var Fluxible = require('./lib/Fluxible');
Fluxible.Fluxible = require('./lib/Fluxible');
Fluxible.contextTypes = require('./lib/contextTypes');
// DEPRECATIONS
// @TODO(next minor): remove all deprecations
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define(factory);
else if(typeof exports === 'object')
exports["Fluxible"] = factory();
else
root["Fluxible"] = factory();
})(this, function() {
@mridgway
mridgway / BundlePlugin.js
Last active January 11, 2024 06:05
Bundle Plugin for Fluxible
/**
* On server, just register all of the resources directly to the plugin. On the client, pass in a loader file that maps bundle
* name to webpack bundle require (a separate entry point). Then from your action, you can call `context.loadBundle` to load
* the bundle resources. On the server, the resources are already available but on the client they will be lazy loaded by
* webpack.
*/
'use strict';
var debug = require('debug')('BundlePlugin');
var PromiseLib = global.Promise || require('es6-promise').Promise;
'use strict';
var bluebird = require('bluebird');
module.exports = function promisifyPlugin(options) {
options = options || {};
/**
* @class PromisifyPlugin
*/
return {
name: 'PromisifyPlugin',
[{"id":"m_1","authorName":"Bill","text":"Hey Jing, want to give a Flux talk at ForwardJS?","timestamp":1415178357749},{"id":"m_2","authorName":"Bill","text":"Seems like a pretty cool conference.","timestamp":1415178367749},{"id":"m_3","authorName":"Jing","text":"Sounds good. Will they be serving dessert?","timestamp":1415178377749},{"id":"m_4","authorName":"Bill","text":"Hey Dave, want to get a beer after the conference?","timestamp":1415178387749},{"id":"m_5","authorName":"Dave","text":"Totally! Meet you at the hotel bar.","timestamp":1415178397749},{"id":"m_6","authorName":"Bill","text":"Hey Brian, are you going to be talking about functional stuff?","timestamp":1415178407749},{"id":"m_7","authorName":"Brian","text":"At ForwardJS? Yeah, of course. See you there!","timestamp":1415178417749}]
diff --git a/lib/route.js b/lib/route.js
index 673bc7c..86835f1 100644
--- a/lib/route.js
+++ b/lib/route.js
@@ -183,7 +183,8 @@ function getResourceRoute(stores) {
function postRoute(stores) {
return function (req, res) {
- var api_requests = {},
+ var timer = req.perf.start(req.id || 'td-api', 'xhr_lifetime'),