Skip to content

Instantly share code, notes, and snippets.

View zerobias's full-sized avatar
💭
Set your status

Dmitry zerobias

💭
Set your status
View GitHub Profile
@zerobias
zerobias / Dynamic spawn in effector.md
Last active April 12, 2024 10:14
Dynamic spawn in effector

Привет! Хочу описать ситуацию с моделями и динамическим спавном: хочется сделать это в ближайшее время. Мы в комитете эффектора рассмотрели ряд апи, все по своему интересны, но в целом не были учтены три главные проблемы, хочу их озвучить для вас, может вам придет что-то на ум)

Спавн моделей будет работать примерно как вызов fork для каждого инстанса. Тело фабрики при этом вызывается один раз, то есть юниты не пересоздаются, все как мы привыкли. Разница в том, что статические фабрики можно спавнить радикально эффективнее, разница как с первой версией fork с линейной сложностью и текущей которую в принципе малореально увидеть на мониторинге приложения.

Итак, проблемы которые нужно решить проектируя апи:

Первая проблема

Как пробрасывать аргументы в фабрику, которая вызывается один раз?

Нужно так или иначе сделать все аргументы сторами и возникает вопрос как сделать это удобнее всего?

@zerobias
zerobias / db.ts
Created September 29, 2023 17:07
Indexed DB with effector
import {createEvent, Event} from 'effector'
type DOMEvent = globalThis.Event
type Deferrable<Done, Fail> = {
addEventListener(event: 'success', handler: (val: Done) => any): any
addEventListener(event: 'error', handler: (err: Fail) => any): any
}
type ObjectDB = {
@zerobias
zerobias / htmlToForestPlugin.js
Last active August 21, 2023 19:26
HTML to forest rollup plugin
import {parseFragment} from 'parse5'
import generate from '@babel/generator'
import {parse} from '@babel/parser'
import t from '@babel/types'
import traverse from '@babel/traverse'
import template from '@babel/template'
function addFactoryImport(path, defs) {
const programPath = path.find(path => path.isProgram())
@zerobias
zerobias / toposort.ts
Created March 21, 2021 14:14
Topological sorting
export function toposort(
rawGraph: Record<string, string[]>,
ignore?: Set<string>
) {
const graph = {} as Record<string, string[]>
for (const id in rawGraph) {
graph[id] = [...new Set(rawGraph[id])]
}
const result = [] as string[]
const visited = {} as Record<string, boolean>
@zerobias
zerobias / server.js
Created February 16, 2021 12:54
server sent events with effector
const express = require('express')
const {createStore, createEvent, sample} = require('effector')
const clientConnected = createEvent()
const statusRequested = createEvent()
const updateReceived = createEvent()
const clientClosed = createEvent()
const pushUpdate = createEvent()
const clients$ = createStore([])
.on(clientConnected, (list, client) => [...list, client])
@zerobias
zerobias / safe-padding.css
Last active March 9, 2020 12:12
Safe body paddings with env() and max() support
/* size variables */
:root {
--md: 8px;
--md-2: calc(var(--md) * 2);
--md-3: calc(var(--md) * 3);
--md-4: calc(var(--md) * 4);
}
/* safe area defaults */
@zerobias
zerobias / bar.f12f7610.js
Created February 26, 2020 15:43
parcel 2 dynamic import
parcelRequire.registerBundle('e1095da0325446888ed16378b7e22c16', function() {
var e =
'undefined' != typeof globalThis
? globalThis
: 'undefined' != typeof self
? self
: 'undefined' != typeof window
? window
: 'undefined' != typeof global
? global
@zerobias
zerobias / hear-dom.js
Created February 15, 2020 22:05
Hear DOM changes with WebAudio API
/*
Copy this into the console of any web page that is interactive and doesn't
do hard reloads. You will hear your DOM changes as different pitches of
audio.
I have found this interesting for debugging, but also fun to hear web pages
render like UIs do in movies.
*/
const audioCtx = new (window.AudioContext || window.webkitAudioContext)()
const observer = new MutationObserver(function(mutationsList) {
@zerobias
zerobias / decompress.js
Created December 27, 2019 10:17
decompress effector repl sources
const keyStrUriSafe =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$'
const baseReverseDic = {}
const charAt = (str, i) => str.charAt(i)
for (let i = 0; i < keyStrUriSafe.length; i++) {
baseReverseDic[charAt(keyStrUriSafe, i)] = i
}
console.log(decompress(localStorage.getItem('code-compressed')))
@zerobias
zerobias / lsdb.ts
Created November 27, 2019 12:27
Reactive database with localStorage and effector
import {
createEvent,
createStore,
createEffect,
combine,
forward,
Effect,
Store,
Event,
step