Skip to content

Instantly share code, notes, and snippets.

View peterpme's full-sized avatar
🏠
Working from home

Peter Piekarczyk peterpme

🏠
Working from home
View GitHub Profile
@peterpme
peterpme / PatternMatching.re
Created May 13, 2020 23:18
ReasonML Pattern Matching
type action = Toggle | Close | Edit;
let reducer = switch(action) {
| Toggle => "toggle visibility"
| Close => "close me"
| Edit => "edit function"
};
let (result) = useQuery(ComponentList.definition);
switch(result) {
| Loading => <LoadingSpinner />
| Error(err) => <ErrorMessage message={err##message} />
| Data(data) => {
switch(data##componentsList) {
| None => []
| Some(components) => components->Belt.Array.map(component => <div> component##value </span>
}
@peterpme
peterpme / InteriorLayout.re
Created December 13, 2018 15:55
ReasonReact render props
[@genType]
let make = (~render, ~children) => {
...component,
render: _self =>
<div className="InteriorLayout">
{render()}
</div>,
};
@peterpme
peterpme / Broken-Navigator.bs.js
Last active October 26, 2018 16:38
Using match_, match in Reason Bug. `Broken-` prefix console.log(match) = undefined
// Generated by BUCKLESCRIPT VERSION 4.0.5, PLEASE EDIT WITH CARE
import * as React from 'react'
import * as ReasonReact from 'reason-react/src/ReasonReact.js'
require('./Navigator.css')
var component = ReasonReact.statelessComponent('Navigator')
function make(history, match__, _) {
@peterpme
peterpme / black-bg.js
Created September 14, 2018 02:09
black-bg
document.body.style.backgroundColor = 'black'
@peterpme
peterpme / withLoadingScreen-4.js
Created April 23, 2018 13:47
Loading Screen with Naming
import * as React from "react";
import hoistNonReactStatics from 'hoist-non-react-statics';
import { View, ActivityIndicator } from "react-native";
const withLoadingScreen = (size = "small") => WrappedComponent => {
class LoadingScreen extends React.PureComponent {
render() {
if (this.props.loading) return <ActivityIndicator size={size} color="white" />
return <WrappedComponent {...this.props} />;
}
@peterpme
peterpme / compose-imports.js
Created April 20, 2018 20:30
compose imports from redux / react-apollo
import { compose } from "redux";
import { compose } from "react-apollo";
// your InfoScreen implementation
// bottom of file:
export default compose(
connect(mapStateToProps, mapActionCreators),
withLoadingScreen
)(InfoScreen)
@peterpme
peterpme / withLoadingScreen-3.js
Created April 19, 2018 22:52
withLoadingScreen HOC with options
import * as React from "react";
import hoistNonReactStatics from 'hoist-non-react-statics';
import { View, ActivityIndicator } from "react-native";
const withLoadingScreen = (size = "small") => WrappedComponent => {
class LoadingScreen extends React.PureComponent {
render() {
if (this.props.loading) return <ActivityIndicator size={size} color="white" />
return <WrappedComponent {...this.props} />;
}
@peterpme
peterpme / withLoadingScreen-2.js
Last active April 19, 2018 22:01
withLoadingScreen with hoist-non
import * as React from "react";
import hoistNonReactStatics from 'hoist-non-react-statics';
import { View, ActivityIndicator } from "react-native";
const withLoadingScreen = WrappedComponent => {
class LoadingScreen extends React.PureComponent {
render() {
if (this.props.loading) return <ActivityIndicator size="small" color="white" />
return <WrappedComponent {...this.props} />;
}
@peterpme
peterpme / withLoadingScreen-1.js
Last active April 27, 2018 13:27
withLoadingScreen First pass
import * as React from "react";
import { View, ActivityIndicator } from "react-native";
const withLoadingScreen = WrappedComponent => {
return class LoadingScreen extends React.PureComponent {
render() {
if (this.props.loading) return <ActivityIndicator size="small" color="white" />
return <WrappedComponent {...this.props} />;
}
};