Skip to content

Instantly share code, notes, and snippets.

View mattmccray's full-sized avatar

Matt McCray mattmccray

View GitHub Profile
@mattmccray
mattmccray / useStreamedState.ts
Last active June 17, 2020 23:07
useStreamedState
import * as React from 'react'
import { stream, scan } from 'flyd'
import merge from 'mergerino'
interface StreamedStateConfigObject<T, A> {
state: T, actions: (updater: (value: Partial<T>) => void) => A
}
type StreamedStateConfigBuilder<T, A> = () => StreamedStateConfigObject<T, A>
@mattmccray
mattmccray / Test.react
Created June 6, 2020 19:50
Single-File React Component - Example (idea)
<script role="view">
import { store, view } from 'react-easy-state'
const counter = store({
value: 0,
increment() { counter.value += 1 },
decrement() { counter.value -= 1 }
})
export default view(() => (
@mattmccray
mattmccray / bulma-prefers-dark-tweaks.css
Created June 4, 2020 03:07
Tweaks for bulma-prefers-dark
* {
scroll-behavior: smooth;
box-sizing: border-box;
}
.modal-card {
box-shadow: 0px 6px 8px rgba(0,0,0,.5);
border-radius: 6px;
}
@mattmccray
mattmccray / DialogManager.js
Last active June 4, 2020 16:12
DialogManager with support for bulma and animation via Animate.css
import React, { useCallback, createContext, useEffect, createRef, Fragment } from 'react'
import { createPortal } from 'react-dom'
import { store, view } from '@risingstack/react-easy-state'
const DIALOG_CANCEL = Symbol("Dialog(cancel)")
const INTERNALS = Symbol("Dialog(internals)")
const DialogContext = createContext()
const state = store({
dialogs: [],
@mattmccray
mattmccray / Example.react
Last active November 7, 2019 04:04
Proposal for a .react single file component that doesn't suck.
<script>
import React from 'react'
import styles from './'
export default () => {
const [items, setItems] = React.useState([{id:1, text: 'First'}])
return (
<div className={styles.Test}>
<header>This is a Test</header>
@mattmccray
mattmccray / EmailAddressList.tsx
Last active October 16, 2019 18:19
Example "Smart Component"
import React from 'react'
import { UIController, useController } from '../core'
import { stylesheet } from '../theme'
import { DomainObjectList } from 'fp-api'
type EmailAddressListProps = {
customerId: number
}
class EmailAddressListController extends UIController<EmailAddressListProps> {
@mattmccray
mattmccray / Events.gd
Created October 2, 2019 22:52
KISS Event Bus for Godot.
extends Node
# Be sure to AutoLoad me as a singleton
# Enumerate all your game events here...
enum {
GAME_STARTED,
GAME_OVER
}
@mattmccray
mattmccray / observables.js
Last active November 30, 2019 09:14
Observables: Simple svelte v3 store wrapper that integrates Immer.
import { derive, readable, writable } from 'svelte/store.js'
import { produce } from 'immer'
export const update = produce
export function computed(deps, reactor) {
const source = derive(deps, reactor)
return {
subscribe: source.subscribe,
get snapshot() { return getSnapshot(source) }
@mattmccray
mattmccray / persist.ts
Last active November 5, 2018 22:46
Persist a (react-easy-state) store to localStorage
import { store } from "react-easy-state";
interface PersistAPI<T = any> {
applySnapshot: (data: T) => void
getSnapshot: () => T
isLoaded: boolean
load: () => void
save: () => void
saveImmediately: () => void
}
@mattmccray
mattmccray / DI.ts
Created October 4, 2018 04:28
Keep It Stupid Simple: TypeScript DI
const _constructing: Set<any> = new Set()
const _services: Map<any, any> = new Map()
const _serviceOverrides: Map<any, any> = new Map()
interface Type<T> { new(...args: any[]): T }
function createInstance(CTor: any, args: any[] = []): any {
if (!CTor) {
// debugger
throw new Error(`Null or undefined dependency specified.`)