Skip to content

Instantly share code, notes, and snippets.

Avatar

Carlos Lalimarmo clalimarmo

View GitHub Profile
@clalimarmo
clalimarmo / url_store.js
Last active Sep 21, 2015
Deep Linking with React + Flux, URL Store, for maintaining correct URL state
View url_store.js
(function() {
Dispather.register(function(action) {
if (action.type !== 'navigate') {
return;
}
window.history.pushState({}, '', action.path);
});
})();
@clalimarmo
clalimarmo / task_store.js
Last active Sep 21, 2015
Deep Linking with React + Flux, Task Store, modified to route on "navigate" Actions
View task_store.js
TaskStore = (function() {
var TaskStore = {};
var state = {};
TaskStore.addChangeListener = function() {
// left as an exercise - hint: event emitters
};
TaskStore.addChangeListener = function() {
@clalimarmo
clalimarmo / app_link.jsx
Last active Sep 16, 2015
Deep Linking with React + Flux, AppLink component
View app_link.jsx
@clalimarmo
clalimarmo / tasks_app.jsx
Last active Sep 21, 2015
Deep Linking with React + Flux, main controller view, replace links with AppLink component
View tasks_app.jsx
TasksApp = React.createClass({
getInitialState: function() {
return {
selectedTask: TaskStore.selectedTask(),
tasks: TaskStore.tasks(),
};
},
componentWillMount: function() {
TaskStore.addChangeListener(this.updateState);
},
@clalimarmo
clalimarmo / routes.rb
Created Sep 15, 2015
Deep Linking with React + Flux, example Rails routes definition
View routes.rb
class ExcludeXhr
def matches?(request)
!request.xhr?
end
end
Rails.application.routes.draw do
constraints(ExcludeXhr.new) do
root 'home#index' # home/index just renders our single page client-side app
get '*path', to: "home#index", via: :all
@clalimarmo
clalimarmo / router.js
Last active Sep 15, 2015
Deep Linking with React + Flux, example Router, to be used by a Store
View router.js
// Router exposes two methods:
//
// - register binds regex patterns to callbacks,
//
// - route takes a path, and executes the callback associated
// with the first regex that matches that path
Router = function() {
var instance = {};
@clalimarmo
clalimarmo / task_store.js
Created Sep 15, 2015
Deep Linking with React + Flux, Task Store, step 1
View task_store.js
TaskStore = (function() {
var TaskStore = {};
var state = {};
TaskStore.addChangeListener = function() {
// left as an exercise - hint: event emitters
};
TaskStore.addChangeListener = function() {
@clalimarmo
clalimarmo / tasks_app.jsx
Created Sep 15, 2015
Deep Linking with React + Flux, main controller view, step 1
View tasks_app.jsx
TasksApp = React.createClass({
// all component state originates from TaskStore, upstream
getInitialState: function() {
return {
selectedTask: TaskStore.selectedTask(),
tasks: TaskStore.tasks(),
};
},
// and when the TaskStore's state changes, we update this component's
@clalimarmo
clalimarmo / .dockerignore
Last active Sep 9, 2015
Rails development environment with Docker, minimal .dockerignore
@clalimarmo
clalimarmo / database.yml
Created Sep 9, 2015
Rails development environment with Docker (step 2 - postgres)
View database.yml
default: &default
adapter: postgresql
pool: 5
host: db
username: postgres
timeout: 5000
development:
<<: *default
database: expense_tracker_dev