Skip to content

Instantly share code, notes, and snippets.

Question:

In a generic sense (aka, not within any particular tool or framework, not the behavior of the tool or framework that you work in)...

If you had an HTML file that looked like this:

<!doctype html>
<script type="module">
 export default "jsvalue"
@jamiebuilds
jamiebuilds / 1-state.tsx
Last active March 6, 2019 21:58
Unstated 3.0 proposal
import React from "react"
import { render } from "react-dom"
import { createContextState, useContextState, Provider } from "unstated"
‪let Count = createContextState(0)‬
‪function useCounter() {‬
‪ let [count, setCount] = useContextState(Count)‬
‪ let increment = () => setCount(count + 1)
let decrement = () => setCount(count - 1)

The Challenge

Compare two (or more) tools that are trying to solve a similar set of problems, without discussing any of the following:

  • Community
  • Programming Language
  • Documentation/Examples/Demos/etc
  • Stars/Forks/Downloads/Issues/PRs/Stack Overflow Answers/etc
  • Age/Maturity of tool

A Redux Story

Developer: "Doo Doo Doo... Working on the new Redux rewrite. Gotta write some fetch actions..."

FETCH_USERS -> function fetchUsersAction() {...}
FETCH_PAGES -> function fetchPagesAction() {...}
FETCH_FRIENDS -> function fetchFriendsAction() {...}
FETCH_GROUPS -> function fetchGroupsAction() {...}
FETCH_EVENTS -> function fetchEventsAction() {...}
getMap()
.set(“a”, “A”)
.set(“b”, ”B”)
.set (“etc”, “ETC”);
class AwesomeMap extends Map {
get(key, createValue) {
if (!this.has(key) && createValue) {
let value = createValue();
this.set(key, value);
return value;
} else {
return this.get(key);
}
}

High-level file system organization for company-wide monorepo

The following are some high level options for organizing a company-wide monorepo.

This is assuming use of a multi-package system like Yarn, Bolt, or Lerna.

Option 1: Flat

Keep all of the packages at the top level so that you don't have to navigate deep into folders to find the package you are looking for. It's always one cd package-name away. It does mean that you have to name folders carefully so that related ones get grouped together.

  • /my-website/
    • package.json
    • /src/
      • /pages/
        • index.html
        • about.html
      • /assets/
        • site.css
        • site.js
  • service-worker.js
/my-website/
  package.json
  /src/
    /pages/
      index.html
      about.html
    /assets/
      site.css
 site.js

Symbols

Syntax

let obj = {
  [Symbol('foo')]: 'hello!',
};

class Obj {