Skip to content

Instantly share code, notes, and snippets.

View itsMapleLeaf's full-sized avatar

Darius itsMapleLeaf

View GitHub Profile
@itsMapleLeaf
itsMapleLeaf / EventsTimeline.js
Created February 12, 2018 03:13
React map example
import React from 'react'
const timelineEvents = [
{
date: 'January',
note: 'Words words words',
},
{
date: 'March',
note: 'Scaling open maps for Jakarta flooding — and printed maps',
@itsMapleLeaf
itsMapleLeaf / index.d.ts
Created February 12, 2018 15:59
VanillaTilt type definitions
// Type definitions for vanilla-tilt 1.3
// Project: https://github.com/micku7zu/vanilla-tilt.js
// Definitions by: Livio Brunner <https://github.com/BrunnerLivio>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/**
* A smooth 3D tilt javascript library forked from Tilt.js (jQuery version).
*/
declare namespace VanillaTilt {
/**
import { action, observable } from "mobx"
import { observer } from "mobx-react"
import * as React from "react"
export type FetcherProps<T> = {
longWaitTimeout?: number
fetch: () => Promise<T>
render: (fetchState: FetchState<T>) => React.ReactNode
}
@itsMapleLeaf
itsMapleLeaf / vanilla-tilt.d.ts
Created March 16, 2018 20:52
VanillaTilt fixed definitions
// Type definitions for vanilla-tilt 1.3
// Project: https://github.com/micku7zu/vanilla-tilt.js
// Definitions by: Livio Brunner <https://github.com/BrunnerLivio>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare module "vanilla-tilt" {
/**
* A smooth 3D tilt javascript library forked from Tilt.js (jQuery version).
*/
namespace VanillaTilt {
/**
// *Model represents any piece of data
class TrackModel {
constructor(public data) {
// validate data?
}
}
// *ViewModel represents view state
class TrackListViewModel {
tracks = observable.array<TrackModel>() // rendered by UI
@itsMapleLeaf
itsMapleLeaf / flow-typescript-thoughts.md
Last active August 24, 2018 17:43
Flow and TypeScript: Thoughts

Flow and TypeScript are both fantastic projects with a very noble and ambitious mission: to add static types to JavaScript. After working with the both of them extensively, I've come to the conclusion that, to no offense to the very many smart people working on Flow, there's little reason to choose it over TS for any new project going forward.

Reasons why I believe TS should be chosen over Flow:

  • TS offers significantly more available type definitions for third-party libraries
    • While the validity of this may depend on one's choice of libraries, I've never personally seen a project which had more Flow definitions than TS definitions available for its dependencies.
  • TS offers very powerful features in its type system that are missing from Flow, like conditional types and argument spread types
  • TS gives a stronger developer experience:
    • Refactors:
  • Go to definition (also available with Flow, but slower and doesn't always work)
@itsMapleLeaf
itsMapleLeaf / function-prefixes.md
Created August 25, 2018 18:26
function prefixes and what they mean in my brain
prefix meaning
create creates information
get retreives information
fetch gets something from the network, doesn't store it or anything
load gets something from the network and stores it somewhere
store accepts a value and stores it somewhere
is deals with a boolean state
handle respond to some event
@itsMapleLeaf
itsMapleLeaf / CacheMap.ts
Created September 13, 2018 03:44
a map which creates new items if one isn't found using a given provider
class CacheMap<T, A extends any[]> {
items = new Map<string, T>()
createItem: (key: string, ...args: A) => T
constructor(itemProvider: (key: string, ...args: A) => T) {
this.createItem = itemProvider
}
get(key: string, ...args: A) {
const item = this.items.get(key) || this.createItem(key, ...args)
{
"compilerOptions": {
/* Basic Options */
"target": "esnext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
// "lib": ["dom", "dom.iterable", "esnext"], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
"jsx": "react", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */