Skip to content

Instantly share code, notes, and snippets.

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",
}
*/
View svelte-ssr-css.ts
import { GENERATED_CSS_PREFIX } from "./constants";
import * as uniroll from "uniroll";
import ts from "typescript";
import { svelte } from "./index";
import fetch from "isomorphic-unfetch";
import vm from "vm";
import fs from "fs";
global.fetch = fetch;
View svelte-ssr-test.ts
import * as uniroll from "uniroll";
import ts from "typescript";
import { svelte } from "rollup-plugin-uniroll-svelte";
import fetch from "isomorphic-unfetch";
import vm from "vm";
global.fetch = fetch;
const App = `
<script lang="ts">
export let foo: string;