Skip to content

Instantly share code, notes, and snippets.

View ghengeveld's full-sized avatar

Gert Hengeveld ghengeveld

View GitHub Profile
@ghengeveld
ghengeveld / asyncActionSpec.js
Created June 20, 2016 09:50
How to test an async action (by monkeypatching the dispatch function)
/* async-action.js */
import SomeService from './some-service';
export function doAsync(arg) {
return dispatch => {
// SomeService.doSomething returns a promise which resolves to the passed argument
SomeService.doSomething(arg).then(result => {
const action = { type: 'ASYNC_SUCCESS', payload: result };
dispatch(action);
}).catch(error => {
@ghengeveld
ghengeveld / implicitly_passing_props.js
Created July 22, 2016 09:05
Implicitly passing props
function App(props) {
return <Header title="Fancy" />;
}
function Header(props) {
return <Title {...props} />;
}
function Title(props) {
return <div>{props.title}</div>;
@ghengeveld
ghengeveld / products.json
Created August 16, 2016 13:22
Demo products
{
"products": [
{
"id": 448082,
"title": "GoPro HERO4 Silver",
"price": 36900,
"description": "De GoPro HERO4 Silver is een waardige opvolger van GoPro 3-serie.",
"thumbnail": "https://image.coolblue.io/products/448082?width=200&height=200"
},
{
@ghengeveld
ghengeveld / select-all.js
Last active February 15, 2017 10:34
AngularJS Select All directive
/**
* Directive to instantly enable/disable multiple checkboxes based on a master checkbox.
* Changing slave checkboxes will update the master checkbox accordingly, including the indeterminate state.
*
* Usage example:
*
* <label><input type="checkbox" select-all="theProperties"> Select all</label>
* <div ng-repeat="property in properties">
* <label><input type="checkbox" rel="theProperties" ng-model="property.checked"> {{ property.label }}</label>
* </div>
@ghengeveld
ghengeveld / accordion.js
Created February 1, 2018 20:47
React Accordion
class Accordion extends React.Component {
constructor(props) {
super(props)
this.state = {
activeItem: null,
}
}
toggle = (event, index) => this.setState(state => ({ activeItem: state.activeItem === index ? null : index }))
render() {
return (
@ghengeveld
ghengeveld / Loading.js
Last active February 11, 2019 12:30
Styled loading bar animation
import styled, { keyframes } from "styled-components"
const slide = keyframes`
0% { left: -35%; right: 100%; }
60% { left: 100%; right: -90%; }
100% { left: 100%; right: -90%; }
`
const chase = keyframes`
0% { left: -200%; right: 100%; }
@ghengeveld
ghengeveld / hello.spec.jsx
Created August 28, 2019 20:55
Promise test with Jest
import React from "react"
import { render, unmountComponentAtNode } from "react-dom"
import { act } from "react-dom/test-utils"
let container = null
beforeEach(() => {
// setup a DOM element as a render target
container = document.createElement("div")
document.body.appendChild(container)
@ghengeveld
ghengeveld / README.md
Created September 16, 2019 21:25
Chromatic thank you note

Thanks

Chromatic

Thanks to Chromatic for providing the visual testing platform that helps us catch unexpected changes on time.

@ghengeveld
ghengeveld / api.md
Created September 25, 2019 17:21
Nact API
start(systemName | extension, ...extensions)
stop(actorRef) 
query(actor,msg, timeoutInMs)
dispatch(actor, msg, sender)
spawn(parent, f, name,  properties)
spawnStateless(parent, f, name, properties)
spawnPersistent(parent, f, persistentKey, name, properties)
persistentQuery(parent, f, key, properties) : Promise<Result>
@ghengeveld
ghengeveld / asyncMocks.ts
Last active November 4, 2019 08:34
TypeScript functions to create mock state objects for React Async
export const mockWaiting = (): AsyncInitial<any> => ({
data: undefined,
error: undefined,
initialValue: undefined,
startedAt: undefined,
finishedAt: undefined,
status: "initial",
isInitial: true,
isPending: false,
isLoading: false,