Skip to content

Instantly share code, notes, and snippets.

View mattmccray's full-sized avatar

Matt McCray mattmccray

View GitHub Profile
@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.`)
@mattmccray
mattmccray / BaseGameEvent.cs
Last active September 17, 2018 22:59
Simple event base class for Unity.
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
namespace WizBangify
{
public delegate void Subscription(bool add);
@mattmccray
mattmccray / yaml-frontmatter.js
Last active February 4, 2018 22:07
Updated YamlFrontMatter mode for CodeMirror that includes the trailing "---" in the yaml block.
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function (mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"), require("../yaml/yaml"))
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror", "../yaml/yaml"], mod)
else // Plain browser env
mod(CodeMirror)
@mattmccray
mattmccray / Announcements.cs
Last active November 24, 2017 21:34
Game Event definitions for Drumpf Flinger 9000 (a Unity 3D game)
using UnityEngine;
/*
You could name this class GameEvents or whatever you want. I chose Announcments because
it doesn't conflict with any builtin Unity class names. I can just type 'ann' and my IDE's
auto-complete takes care of the rest.
*/
public static class Announcements
{
public static class Camera