Skip to content

Instantly share code, notes, and snippets.

View kozo002's full-sized avatar

kozo yamagata kozo002

View GitHub Profile
@kozo002
kozo002 / App.tsx
Last active August 28, 2024 00:31
Example context implementation in qwik
import { component$, $, useStore, useContextProvider, createContextId, useContext, Slot } from "@builder.io/qwik";
export function createTab<T extends string[]>(tabKeys: T, initial?: T[number]) {
type TabStore = { activeKey: T[number] }
const TabContext = createContextId<TabStore>('Tab_' + tabKeys.join('_'));
const Tab = component$(() => {
const store = useStore({ activeKey: initial ?? tabKeys[0] })
useContextProvider(TabContext, store)
console.log('hoge')
@kozo002
kozo002 / memoizeSelector.js
Created January 18, 2021 14:29
memoizeSelector
const memoizeSelector = (getDeps, selector) => {
const lastDeps = []
let lastResult
return (store) => {
let updated = false
const deps = getDeps.map((getDep, i) => {
const dep = getDep(store)
if (dep !== lastDeps[i]) {
lastDeps[i] = dep
updated = true
javascript:(function(bgStyle){ window.open(bgStyle.replace(/^url\("/,'').replace(/"\)$/,'').replace('magazine_cover_landscape_', '')+'?crop=1.6:0.27') })(document.querySelector('.o-magazineHeader__cover').style.backgroundImage)
jest.spyOn(file, 'size', 'get').mockReturnValue(10001)
function validateImageSize(file: File): boolean {
return file.size < 10000
}
describe('when the file size is exceeded the limitation', () => {
it('returns false', () => {
const dummyFile = new File([''], 'example.jpg')
dummyFile.size = 10001
expect(validateImageSize(dummyFile)).toBe(false)
})
async function getUser(httpClient: HttpClient, userId: number): Promise<User> {
const res = await httpClient.get(`/api/users/${userId}`)
return res.data.user
}
describe('when the API ends in successful', () => {
it('returns the user data', async () => {
const get = jest.fn(() => {
return Promise.resolve({
data: {
export default defineComponent({
setup() {
const state = reactive({
count: store.state.count,
})
return {
state,
increment() {
store.dispatch('increment')
}
$ bundle exec derailed bundle:mem production
TOP: 63.3555 MiB
rails/all: 18.3711 MiB
rails: 10.6133 MiB (Also required by: active_record/railtie, active_model/railtie, and 13 others)
active_support: 3.8711 MiB (Also required by: active_support/railtie, active_support/i18n_railtie, and 10 others)
active_support/logger: 3.082 MiB
active_support/logger_silence: 2.9805 MiB
concurrent: 2.9258 MiB (Also required by: sprockets/manifest)
concurrent/executors: 1.0586 MiB
concurrent/executor/timer_set: 0.4961 MiB

目次

  1. html, cssコーディング
  2. 静的コンポーネント作成
  3. store設計 (JSON)
  4. storeを参考にactionTypesを作成
  5. actionTypesからactionCreatorsを実装
  6. XHRはmodelに
  7. actionCreatorsreducerを作成
  8. mountComponentとmountComponentWithRedux関数