Skip to content

Instantly share code, notes, and snippets.

import {useEffect} from 'react';
type EventKey = string;
type EventHandler<T = any> = (payload: T) => void;
type EventMap = Record<EventKey, EventHandler>;
type Bus<E> = Record<keyof E, E[keyof E][]>;
interface EventBus<T extends EventMap> {
on<Key extends keyof T>(key: Key, handler: T[Key]): () => void;
off<Key extends keyof T>(key: Key, handler: T[Key]): void;
@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])
@e-minguez
e-minguez / 01-podman-pod-nextcloud.md
Last active November 12, 2023 09:31
podman pod nextcloud
  • Some variables to avoid writting too much and create some folders:
export PODNAME="nextcloud"
mkdir -p ~/containers/nextcloud/{db,nginx,html}
  • Copy the nginx.conf file:
@aspnetde
aspnetde / mvu.tsx
Created September 6, 2020 22:23
Pragmatic MVU With React And TypeScript
import React, { useReducer } from "react";
interface State {
userName: string;
password: string;
isValid: boolean;
}
const initialState: State = {
userName: "",
@doasync
doasync / fry.js
Last active September 3, 2020 12:13
fry with interceptors
'use strict';
const queryString = (params) => {
const qs = String(new URLSearchParams(params));
return qs ? `?${qs}` : "";
};
const joinBase = (url, baseUrl) =>
`${baseUrl.replace(/\/$/, "")}/${url.replace(/^\/|\/$/, "")}/`;
@doasync
doasync / request.js
Last active May 29, 2020 10:39
Axios-like fetch
const queryString = (params) => {
const qs = String(new URLSearchParams(params));
return qs ? `?${qs}` : "";
};
const joinBase = (url, baseUrl) =>
`${baseUrl.replace(/\/$/, "")}/${url.replace(/^\/|\/$/, "")}/`;
const contentTypeJson = { "Content-Type": "application/json" };
const d = createDomain();
d.onCreateStore((store) => {
store.updates.watch((value) => {
console.log(`STORE ${store.shortName} UPDATED`, value);
});
});
d.onCreateEvent((event) => {
event.watch((parameters) => {
@popuguytheparrot
popuguytheparrot / file.js
Last active March 4, 2021 13:24
ws store effector
import { createEffect, createEvent, createStore, merge } from 'effector';
import nanoid from 'nanoid';
import { request, parseObject } from 'jsonrpc-lite';
const wsURL = `ws://localhost:${process.env.WS_PORT}`;
let socket;
const awaitingMap = new Map();
function cleanSocket() {
@Tauka
Tauka / effector-store-structure.js
Created July 22, 2019 09:06
Example structuring store in one file
import { createStore, createEvent, createEffect } from 'effector';
import { $problemId } from './problem';
import { createApiStore } from 'utils/store';
import { submitApi, runCodeApi } from 'api';
import { batchCombine } from 'utils/effector';
/**
* EVENTS, EFFECTS
* ----------------------------------------------------------------------------
@popuguytheparrot
popuguytheparrot / useWS.js
Last active March 6, 2024 16:25
websocket hook with effector
import { useEffect, useRef, useCallback } from 'react';
import { createEvent, createStore } from 'effector';
import { useStore } from 'effector-react';
const open = createEvent('open');
const closed = createEvent('closed');
const error = createEvent('error');
const wsStatus = createStore('closed')