Skip to content

Instantly share code, notes, and snippets.

View innerdaze's full-sized avatar
👾

Lee Driscoll innerdaze

👾
  • Acre Software
  • Bournemouth, UK
View GitHub Profile
@innerdaze
innerdaze / package.json
Last active March 15, 2018 12:20
Simple build system for babel
{
"main": "dist/index.js",
"scripts": {
"transpile": "babel src/index.js",
"prebuild": "shx mkdir -p dist",
"build": "npm run transpile -- -o dist/index.js",
"start:dev": "babel-node src/index.js",
"watch": "nodemon -w src/* -x \"npm run build &> /dev/null && node .\""
},
"devDependencies": {
@innerdaze
innerdaze / reducers.js
Created March 14, 2018 09:39
Wastage Reducers
import { handleActions } from 'redux-actions'
import { combineReducers } from 'redux'
import { pluck, indexBy, prop, assocPath, without, of, dissoc } from 'ramda'
import actions from './actions'
const { wastage } = actions
const wastageTypesInitialState = {
isFetching: false,
didInvalidate: false,
@innerdaze
innerdaze / index.js
Created March 14, 2018 09:33
Wastage Fixtures
import faker from 'faker'
import { compose, map, applySpec, always } from 'ramda'
// TODO: Write MockModel Class to code gen the generate methods
// Wastage
export const wastageModel = {
_id: faker.random.uuid,
StoreID: faker.random.alphaNumeric,
ProductID: faker.random.alphaNumeric,
@innerdaze
innerdaze / operations.js
Created March 14, 2018 09:25
Wastage Operations
import { pluck } from 'ramda'
import { callApi } from '~features/network/operations'
import { orderOperations, orderSelectors } from '~features/order'
import actions from './actions'
import selectors from './selectors'
const wastageActions = actions.wastage
export const fetchWastageTypes = () => dispatch => {
dispatch(wastageActions.requestWastageTypes())
@innerdaze
innerdaze / reducers.test.js
Created March 13, 2018 09:10
Example Reducer Test
import { pluck, indexBy, prop } from 'ramda'
import operations from '../operations'
import {
wastageTypes as wastageTypesReducer,
wastageProcessing as wastageProcessingReducer,
wastageEntities as wastageEntitiesReducer
} from '../reducers'
import {
generateWastage,
generateWastageTypeArray,
@innerdaze
innerdaze / thunks.test.js
Created March 13, 2018 08:48
Example Thunk Testing
import configureMockStore from 'redux-mock-store'
import thunk from 'redux-thunk'
import fetchMock from 'fetch-mock'
import expect from 'expect'
import { indexBy, pluck, prop } from 'ramda'
import operations from '../operations'
import { generateWastageTypeArray, generateWastageArray } from '../__fixtures__'
const middleWares = [thunk]
const mockStore = configureMockStore(middleWares)
@innerdaze
innerdaze / thunks.test.js
Created March 6, 2018 12:20
Using fetch-mock to test thunks
import configureMockStore from 'redux-mock-store'
import thunk from 'redux-thunk'
import fetchMock from 'fetch-mock'
import expect from 'expect'
import { indexBy, pluck, prop } from 'ramda'
import operations from '../operations'
import { generateWastageTypeArray, generateWastageArray } from '../__fixtures__'
const middleWares = [thunk]
const mockStore = configureMockStore(middleWares)
@innerdaze
innerdaze / fixtures.js
Last active March 5, 2018 10:34
Using Faker & Ramda to generate fixtures
import faker from 'faker'
import { compose, map, applySpec, always } from 'ramda'
/**
* Usage:
*
* import { generateWastage, generateWastageArray } from './fixtures
*
* const wastageFixture = generateWastage()
* const wastageFixtures = generateWastageArray(3)
@innerdaze
innerdaze / OrderMeta.jsx
Last active February 27, 2018 16:49
Different Component Structure with Ramda
import React from 'react'
import { map, apply, zip, times } from 'ramda'
import { v4 } from 'uuid'
import Box from 'grommet/components/Box'
const propArray = [
'Supplier Code',
'PackSize',
'In Stock',
'On Order',
@innerdaze
innerdaze / ProgressPromiseBabel.js
Last active February 23, 2018 21:19
Replacement for progress-promise that works with Uglify
const ProgressPromise = {
/**
* Process a list of Promises asynchronously and report the progress after each Promise completes
*
* @param {Promise[]} promises. An array of promise to execute - are passed internally to Promise.all.
* @param {Function} reporter.
* A function that will be executed after each promise completes that receives the proportion of
* completed promises as a decimal
* @return {Promise}
*/