Skip to content

Instantly share code, notes, and snippets.

View atticoos's full-sized avatar
🧑‍💻
building Rally

Atticus White atticoos

🧑‍💻
building Rally
View GitHub Profile
function MyComponent ({spaceId}) {
const [space, loading, error] = useSpace(spaceId);
if (loading) return <Loading />
if (error) return <Error />
return <SpaceCard space={space} />
}
function useSpace (spaceId) {
const dispatch = useDispatch();
@atticoos
atticoos / jest.config.js
Created January 17, 2019 18:53
WTF LERNA+JEST
// jest.config.js
module.exports = {
projects: [
'<rootDir>/packages/design-system/jest.config.js'
],
transform: {
'^.+\\.jsx?$': '<rootDir>/jest-babel-transformer'
},
moduleFileExtensions: ['js', 'jsx']
}
@atticoos
atticoos / graphql-delegation.js
Last active September 22, 2018 18:56
Experimenting with GraphQL for https://docs.robinpowered.com/
const spaceSchema = makeExecutableSchema({
typeDefs: `
type Space {
id: Int!
name: String
location_id: Int!
}
type Query {
spaceById(id: Int!): Space
@atticoos
atticoos / props-as-style-overrides.js
Last active February 5, 2018 15:46
Example HoC for style-properties
function withPropsAsStyleOverrides (WrappedComponent) {
return ({style, ...props}) => {
// make style spreadable
style = Array.isArray(style) ? style : [style]
// split the incoming properties into a style and forward group
const {styleProps, forwardProps} = Object.keys(props).reduce((split, key) => {
if (isStyleProp(key)) {
split.styleProps[key] = props[key]
} else {
public class ImmersiveModeModule extends ReactContextBaseJavaModule {
public static final String TAG = "ImmersiveMode";
private Handler uiHandler;
private Runnable mRunnable;
public ImmersiveModeModule(ReactApplicationContext reactContext) {
super(reactContext);
uiHandler = new Handler(reactContext.getMainLooper());
@atticoos
atticoos / serial-callbacks.js
Created September 21, 2017 16:00
Allows passing a callback serially between two systems
var seed = 0;
var callbacks = new Map();
function registerCallback (cb) {
if (callbacks.has(cb)) {
return callbacks.get(cb)
}
var id = ++seed;
callbacks.set(cb, id)
@atticoos
atticoos / redux.js
Created July 13, 2017 20:28
Reusable reducers
// creates a reducer that registers, unregisters, and routes component-specific state
function createMultiUseReducer (group, reducer) {
return (managedStates = {}, action) {
// register state for a new component
if (
action.type === 'REGISTER_REUSABLE_COMPONENT' &&
action.group === group
) {
return {
'use strict';
import * as Reselect from 'reselect';
export function createSelector (...args) {
const selector = Reselect.createSelector(...args);
var debug = false;
var debugLabel = null;
function debuggableSelector (...selectorArgs) {
@atticoos
atticoos / bad.js
Last active June 5, 2017 22:58
Optional object dangers
{
If(this.props.person) (
<Text>Hello, {this.props.person.name}</Text> // This still gets unsafely evaluated!
)
}