Skip to content

Instantly share code, notes, and snippets.

View how_to_use_deno_snapshot.rs
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
use deno_core::{JsRuntime, RuntimeOptions, Snapshot};
fn main() {
// create snapshot
let mut runtime = JsRuntime::new(RuntimeOptions {
will_snapshot: true,
..Default::default()
});
View context_store.ts
type EventBase = {
__uid?: string;
__ts?: number;
};
type PubSub<Event> = {
dispatch: (ev: Event) => void;
subscribe: (fn: (ev: Event) => void) => void;
};
View select-frontend-tech.md

フロントエンドの技術選定で考えること

Frontend Study 用

前提: フロントエンドは式年遷宮が有効である

  • DB を持たないため、表層の技術を交換するだけで済む
    • JSON API が実質的な分解点になっている
    • 近年ではモバイルアプリのために JSON API が切り離されていることが多く、ここの利用者になるだけでよい
    • Rails や PHP で ORM ヘルパーにべったりな場合に困難になる(クライアントで同等のバリデーションを再現する必要)
View runGraphqlCodegen.ts
import { graphql, parse } from "graphql";
import gql from "graphql-tag";
import type { DocumentNode } from "graphql";
const documentNode = gql`
type Query {
userData(q: UserDataQuery!): UserData!
template(source: String!, args: [UserDataQuery!]!): ExpandedTemplate!
}
View wc_dispatchable_svelte_component.svelte
<svelte:options tag="my-dispatcher-button" />
<script lang="ts">
import { get_current_component } from "svelte/internal";
const component = get_current_component();
const onClick = () => {
component?.dispatchEvent(new CustomEvent("emit", { detail: { foo: 1 } }));
};
</script>
View clone-and-reflect.ts
import { h, render } from "preact";
import { useState } from "preact/hooks";
// Original App
function App() {
const [state, setState] = useState(0);
return h(
"div",
{ class: "root" },
h(
View vite-plugin-raw.js
// vite-plugin-raw
/*
How to use.
// vite.config.js
const raw = require('<this>')
module.exports = {
plugins: [raw()]
View gist:3b8c9545dd974a00d130fac1ba9ecc7d
$ rustc -V
rustc 1.52.0-nightly (e9920ef77 2021-02-11)
$ cargo install pijul --version "~1.0.0-alpha
...
Compiling pijul v1.0.0-alpha.45
error: linking with `cc` failed: exit code: 1
View rewrite-ts.js
/*
Patch typescript to run in snowpack.
I added this workaround for perf_hooks.
Add this task in package.json
"scripts": {
// ...
"postinstall": "node scripts/rewrite-ts.js",
}
*/