Skip to content

Instantly share code, notes, and snippets.

View owanturist's full-sized avatar

Anton Ovechkin owanturist

  • StackState
  • Diemen, the Netherlands
View GitHub Profile
@owanturist
owanturist / Box.tsx
Created September 23, 2022 05:43
Polymorphic Box component
// https://github.com/ohansemmanuel/polymorphic-react-component
import React from "react";
type PolymorphicRef<TComponent extends React.ElementType> = React.ComponentPropsWithRef<TComponent>["ref"];
type AsProp<TComponent extends React.ElementType> = {
as?: TComponent;
};
@owanturist
owanturist / micro-store.ts
Last active November 20, 2021 14:37
A lightweight and performant React global state management
/* eslint-disable no-console */
import {
Dispatch,
SetStateAction,
useRef,
useReducer,
useEffect,
useCallback
} from 'react'
type FrontendMsg
= FNoop
| Increment
| Decrement
| OnBackendMsg ToFrontend
update : FrontendMsg -> Model -> ( Model, Cmd FrontendMsg )
update msg model =
case msg of
FNoop ->
/* @flow */
const curryResolver = (fn, arity, mem) => (...args) => {
const resultArgs = args.concat(mem);
return resultArgs.length >= arity
? fn(...resultArgs)
: curryResolver(fn, arity, resultArgs)
};
type Attribute<Msg>
= VEvent<Msg>
;
type Decoder<Msg> = (event: Event) => Msg;
interface VEvent<Msg> {
type: 'V_EVENT';
key: string;
value: {
@owanturist
owanturist / Main.elm
Created July 7, 2016 13:30
Simple elm-app with normalized store
module Main exposing (main)
import Html.App
import Html exposing (Html, div, ul, li, form, input, button, strong, text)
import Html.Events exposing (onSubmit, onInput)
import Html.Attributes exposing (type', value)
import Dict exposing (Dict)
-- MODEL