Skip to content

Instantly share code, notes, and snippets.

@wycats
wycats / 1-unannotated.jsx
Created Sep 2, 2022
An explanation of how Starbeam integrates with React 18's reusable state (https://github.com/reactwg/react-18/discussions/19)
View 1-unannotated.jsx
import { Cell } from "@starbeam/core";
import { useSetup } from "@starbeam/react";
const SYSTEM_LOCALE = Intl.DateTimeFormat().resolvedOptions().locale;
const SYSTEM_TZ = Intl.DateTimeFormat().resolvedOptions().timeZone;
function Clock({ locale = SYSTEM_LOCALE, timeZone = SYSTEM_TZ }) {
const now = useSetup((component) => {
const now = Cell(new Date()));
View components.my-lol\.js
import Component from '@glimmer/component';
export default class extends Component {
}
@wycats
wycats / 1-js.js
Created Jul 30, 2020
alternative observer design
View 1-js.js
// observed popover is interested in changes to `width` and `height` relative to the
// page's origin, and normalized by rounding them to the nearest integer.
let observedPopover = new RectObserver(
popoverElement,
{
width: Math.round,
height: Math.round
},
{
relativeTo: 'origin' // not viewport
View controllers.application.js
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
value: 'Hello world',
inputted(e) {
Ember.set(this, 'value', e.target.value);
}
});
View js.ts
// default tagName is 'div'
// The problem
function createElement(tagName: string): Element {
// very broken
return document.createElement(tagName || 'div');
}
// you might want to use defaults
View components.my-component.js
import Ember from 'ember';
export default Ember.Component.extend({
});
View monad-stuff.ts
import { unknown } from 'ts-std';
import { ErrorMessage } from "monad-test";
export type ErrorPath = ReadonlyArray<string>;
export interface ErrorMessage {
key: string;
args: unknown;
}
View adapters.secure-message.js
import FirebaseAdapter from 'emberfire/adapters/firebase';
export default FirebaseAdapter.extend({
});
View rails-creed.md

The Ember Creed

  1. Optimize for programmer happiness
  2. Convention over configuration
  3. The menu is omakase
  4. No one paradigm
  5. Exalt beautiful code
  6. Provide sharp knives
  7. Value integrated systems
  8. Stability without Stagnation
View controllers.application.js
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});