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 / nicknames.md
Last active June 16, 2022 07:44
nicknames
16.06.2022
Дима Zerobias
01.03.2022
⛴➡️🍆
@zerobias
zerobias / h.ts
Last active April 18, 2022 08:23
Declarative stack-based DOM api
import {
createStore,
createEvent,
is,
clearNode,
forward,
sample,
Store,
Event,
launch
@zerobias
zerobias / BinarySearchTree.js
Created August 11, 2018 10:10
Binary Search Tree
/**
* A binary search tree implementation in JavaScript. This implementation
* does not allow duplicate values to be inserted into the tree, ensuring
* that there is just one instance of each value.
* @class BinarySearchTree
* @constructor
*/
class BinarySearchTree {
constructor() {
/**
@zerobias
zerobias / Graph.js
Created August 27, 2018 06:09 — forked from netgusto/Graph.js
Graph Data Structure, adjacency list implementation + Traversals (DFS, BFS)
module.exports = class Graph {
constructor(V, E, directed = false) {
this.vertices = V;
this.edges = {};
E.map(e => {
const a = e[0]; const b = e[1]; const w = e[2] === undefined ? 1 : e[2];
this.addEdge(a, b, w);
@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 / 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 / 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>