Skip to content

Instantly share code, notes, and snippets.

View kandros's full-sized avatar
:bowtie:
o.o

Jaga Santagostino kandros

:bowtie:
o.o
View GitHub Profile
@kandros
kandros / code.js
Last active August 11, 2016 20:34
testing the obvious
function fetchAllProjects() {
return dispatch => {
console.log('1')
dispatch(xxx())
dispatch({ type: 'REQUEST_ALL_PROJECTS' });
console.log('2')
ProjectsApi.getAllProjects()
.then(projects => {
dispatch({ type: 'SUCCESS_ALL_PROJECTS', projects: fromJS(projects) });
})
@kandros
kandros / mongoose-findOrCreate.js
Created October 9, 2016 23:05 — forked from niksumeiko/mongoose-findOrCreate.js
Mongoose schema static `findOrCreate` method in ES6/7 async/await syntax
import mongoose from 'mongoose';
let schema = new mongoose.Schema({
email: { type: String, required: true, unique: true },
password: { type: String, required: true }
});
schema.statics.findOrCreate = async (conditions, opt_attr) => {
let document = await User.findOne(conditions);
@kandros
kandros / Ref.js
Created January 29, 2017 21:41 — forked from ryanflorence/Ref.js
import React, { PropTypes, Component } from 'react'
import { getRef, listToArray } from '../utils/firebase'
import { ErrorMessage, Loading } from '../Theme'
/*
```js
<Ref path="/somewhere">
{({ error, loaded, value }) => (
// `value` is an object w/ keys
@kandros
kandros / foo.js
Created January 29, 2017 21:41 — forked from ryanflorence/foo.js
const addAccountToTransactions = (txs, accounts) => (
txs.map(tx => (
// add the relationship
{
...tx,
account: accounts[tx.accountKey]
}
))
)
@kandros
kandros / data.js
Created February 16, 2017 20:29 — forked from ryanflorence/data.js
// routes.js
const routes = [
{
path: '/',
component: Home,
exact: true
},
{
path: '/gists',
component: Gists
@kandros
kandros / redux-is-smarter-than-you-think.md
Created April 14, 2017 14:48 — forked from armw4/redux-is-smarter-than-you-think.md
Optimizing your react components via redux....shouldComponentUpdate for free and more...

The Beginning

Yes...it's true...redux is smart....smarter than you even know. It really does want to help you. It strives to be sane and easy to reason about. With that being said, redux gives you optimizations for free that you probably were completely unaware of.

connect()

connect is the most important thing in redux land IMO. This is where you tie the not between redux and your underlying components. You usually take state and propogate it down your component hiearchy in the form of props. From there, presentational

export default [
'Afghanistan',
'Albania',
'Algeria',
'Andorra',
'Angola',
'Antigua & Deps',
'Argentina',
'Armenia',
'Australia',
export default [
"AFGHANISTAN",
"ALBANIA",
"ALGERIA",
"AMERICAN SAMOA",
"ANDORRA",
"ANGOLA",
"ANGUILLA",
"ANTARCTICA",
"ANTIGUA AND BARBUDA",
@kandros
kandros / interceptors.js
Created July 2, 2017 16:16 — forked from javisperez/interceptors.js
Axios interceptor for cache with js-cache
// Usually I use this in my app's config file, in case I need to disable all cache from the app
// Cache is from `js-cache`, something like `import Cache from 'js-cache';`
const cacheable = true,
cache = new Cache();
// On request, return the cached version, if any
axios.interceptors.request.use(request => {
// Only cache GET requests
if (request.method === 'get' && cacheable) {