Skip to content

Instantly share code, notes, and snippets.

View bfillmer's full-sized avatar

Bryan Fillmer bfillmer

View GitHub Profile
@bfillmer
bfillmer / index.js
Created August 5, 2016 03:02 — forked from jonahwilliams/index.js
Redux with Rxjs
"use strict";
const Rx = require('rx');
const fetch = require('isomorphic-fetch'); /* use the fetch api on client and server */
/**
* Given a subreddit, pull down post ids. that is, changing the subreddit by calling terms$.onNext(SUBREDDITNAME)
* automatically calls the reddit api and populates the store.
* To try it out, npm install rx and isomorphic-fetch, then
* var S = require('./index.js');
* S.store$.subscribe(x => console.log(x)); // listen to every state change
@bfillmer
bfillmer / epic.js
Created August 5, 2016 02:59 — forked from shuhei/epic.js
An idea of side-effect-free epic like redux-saga for redux-observable
// Explicit in-out of side-effect actions.
function epic(action$, store) {
const fooReq$ = action$.ofType('FOO')
.map(action => call('FOO_REQ', webapi.getFoo, action.payload.id));
const foo$ = action$.ofType('FOO_REQ')
.map(foo => ({ type: 'FOO_FETCHED', payload: { foo } }));
return Observable.merge(
fooReq$,
foo$
@bfillmer
bfillmer / observable-store.js
Last active August 4, 2016 21:49 — forked from tungd/observable-store.js
How to use Rx.Observable in-place of Redux store
import update from 'react/lib/update'
import { Observable, Subject, ReplaySubject } from 'rx'
const INITIAL_STATE = {
user: null
}
const updates = new ReplaySubject()
export const state = Observable.of(INITIAL_STATE)
.merge(updates.map(change => state => update(state, change)))

Folder Structure

Motivations

  • Clear feature ownership
  • Module usage predictibility (refactoring, maintainence, you know what's shared, what's not, prevents accidental regressions, avoids huge directories of not-actually-reusable modules, etc)
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
@bfillmer
bfillmer / persistent.filter.js
Created March 4, 2015 17:02
Persistent Filter for Angular ng-repeats.
'use strict';
angular.module('core')
// Persistent filter, runs on any ng-repeat.
.filter('PersistentFilter', ['_', 'PersistentFilterStorage',
function (_, PersistentFilterStorage) {
var pfs = PersistentFilterStorage;
@bfillmer
bfillmer / angular-focus-directive.js
Created August 31, 2014 19:04
Angular JS Focus Directive
(function(){
/**
* Emulates ng-show for focus, i.e.:
*
* <input ng-focus="truthyValue">
*
* Setting truthyValue to true focuses said input.
*/
app.directive('ngFocus', function($timeout){
@bfillmer
bfillmer / angular-wp-factory.js
Created August 28, 2014 15:32
Angular JS WordPress Factory
/**
* Small factory for accessing WP backend AJAX. Best used with the built in admin-ajax.php
* calls.
*
* Controller example:
var myApp = angular.module('myApp', [ 'WP' ]);
myApp.controller('myCtrl', function($scope, WPAjax){
@bfillmer
bfillmer / meta-data.php
Created August 15, 2014 17:31
Quick way to hide protected meta data via a plugin. More robust than the _ prefix.
<?php
add_filter( 'is_protected_meta', 'hide_meta_data', 10, 2 );
/**
* Set our metadata to be protected, will not be seen in administration,
* unless the plugin is deactivated.
* @param array $protected protected values
* @param string $meta_key current meta key
* @return string/bool $protected or true to add
@bfillmer
bfillmer / toolbox.less
Created June 16, 2014 15:45
Generic LESS Mixins
// Liked what Chris Coyier showed off in this blog post:
// http://codepen.io/chriscoyier/blog/some-mini-sass-mixins-i-like
// Decided to make LESS versions really quickly.
.coverer() {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;