Skip to content

Instantly share code, notes, and snippets.

View ORESoftware's full-sized avatar
🏐
Focusing

Alexander Mills ORESoftware

🏐
Focusing
View GitHub Profile
@ORESoftware
ORESoftware / exampleModule.js
Last active May 10, 2016 02:15
Hot reloading with React + RequireJS
define(['require'],function(require){ // 'require' is a reserved dependency keyword in RequireJS
var module = require('someModule'); //if we know for sure that someModule is already loaded, then we can load it here synchrounously
});
@ORESoftware
ORESoftware / example.js
Last active January 22, 2016 02:03
Example RequireJS synchronous call
define(['require'],function(require){ // 'require' is a reserved dependency keyword in RequireJS
//if we know for sure that some-module is already loaded, then we can load it here synchrounously
//we don't even need to reference it in the dependency array above, if we know it's already loaded
var module = require('some-module');
});
@ORESoftware
ORESoftware / gulpfile.js
Created September 6, 2015 23:25
Gulpfile for project
var gulp = require('gulp');
var socketio = require('socket.io');
var EE = require('events').EventEmitter;
var react = require('gulp-react');
var io = socketio.listen('3002', function (err, msg) {
if (err) {
@ORESoftware
ORESoftware / hotReloadHandler.js
Last active September 6, 2015 23:31
hotReloadHandler
define([
'socketio',
'#allCollections',
'#allCSS',
'#hotReload',
'app/js/cssAdder'
],
@ORESoftware
ORESoftware / serviceChooser.js
Last active September 22, 2015 06:40
Service Chooser
define([
'react',
'app/js/jsx/reactComponents/Service' // this 'child view' needs to be loaded before calling render on ServiceChooser, so that we can require it synchronously in the render function
'require'
],
function (React, Service, require) {
@ORESoftware
ORESoftware / allViews.js
Created September 7, 2015 01:23
allViews
//app/js/meta/allViews.js
define([
"app/js/jsx/BaseView",
"app/js/jsx/reactComponents/FluxCart",
"app/js/jsx/reactComponents/FluxCartApp",
"app/js/jsx/reactComponents/FluxProduct",
"app/js/jsx/reactComponents/Item",
"app/js/jsx/reactComponents/Job",
@ORESoftware
ORESoftware / main.js
Last active September 18, 2015 21:39
config
// the # and @ notation is mine just to identify certain modules as my own and to make it easier to grep for things
// as you can see in the bottom of the file, RequireJS loads all dependencies in app/js/application before starting the app
// so if you put #allViews, #allCSS and #allTemplates as dependencies of your app/js/application module then this allows us to preload certain dependences so that we can later use *synchronous* require calls
// the synchronous require calls will allow us to do hot reloading with React and Backbone. We *could* make the render functions asynchronous, but there are two problems with that
// one problem is that Backbone conventions recommend returning 'this' from render(), the second is that React needs you return a valid React component from render, so render has to be synchronous
@ORESoftware
ORESoftware / application.js
Last active September 18, 2015 21:33
application
define(
[
'*windowPatches',
'*backbonePatches',
'*jsPatches',
'observe',
'backbone',
'jquery',
@ORESoftware
ORESoftware / read_SE_API.js
Last active July 14, 2017 09:43
StackExchange API Node.js
/**
* Created by amills001c on 9/15/15.
*/
var url = 'http://api.stackexchange.com/2.2/answers?order=desc&sort=activity&site=stackoverflow';
var http = require("http");
var zlib = require("zlib");
@ORESoftware
ORESoftware / hotReloader.js
Created September 22, 2015 06:29
hotReloader.js
define(function () {
var hotReloadSimple = function (item, callback) {
require.undef(item); //delete cache representing module; this means the next require call to the same module will then have to pull the module from filesystem
require([item], function (module) { //load the file asynchronously, because the cache has been deleted
callback(null, module);
});
};