Skip to content

Instantly share code, notes, and snippets.

View kobzarvs's full-sized avatar

Valeriy Kobzar kobzarvs

View GitHub Profile
import { createStore, createEvent, is, fork, allSettled } from 'effector';
import { produce } from 'immer';
function createCollection(store, events) {
const collection = createStore({});
const setStoreValue = createEvent();
store.on(setStoreValue, (state, value) => value);
let length = 0;
let keys = [];
export class AsyncTaskSeq {
last = Promise.resolve();
add(task: () => Promise<void>) {
const sync = this.last;
this.last = new Promise(async (resolve, reject) => {
try {
await sync;
await task();
resolve();
import { attach, createEffect } from 'effector';
import { HTTP_METHOD, RequestFxParams, ResponseError, User } from './types';
import { $session } from '../models/session';
export const GET = 'GET';
export const POST = 'POST';
export const PUT = 'PUT';
export const DELETE = 'DELETE';
const URL = 'https://api.realworld.io/api';
_try = (cb) => {
let error;
try {
cb();
} catch(e) {
error = e;
}
const result = {
catch: (err, handler) => {
@kobzarvs
kobzarvs / app.tsx
Last active January 18, 2022 17:50
Простой пример использования effector-logger & effector-inspector без babel-plugin
import React from 'react';
import { useEvent, useStore } from 'effector-react';
import { $counter, dec, inc, reset } from './counter';
export const App = () => {
const counter = useStore($counter);
const api = useEvent({ inc, dec, reset });
return (
<div>
@kobzarvs
kobzarvs / loadModule.js
Created March 28, 2020 18:13
effector - загрузка npm пакетов и пример three.js
async function loadModule(url, removeExports) {
delete window.exports
const text = await (await fetch(url)).text()
window.eval(text)
return text
}
await loadModule('https://threejs.org/build/three.js')
await loadModule('https://cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js')
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CandleStick Chart</title>
<style>
#chart {
border: 1px solid red;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CandleStick Chart</title>
<style>
#chart {
border: 1px solid red;
.button {
border: 1px solid #555;
text-align: center;
padding: 0 12px;
color: #ddd;
cursor: pointer;
}
.button:hover {
background: rgba(255, 255, 255, .25)
.button {
border: 1px solid #555;
text-align: center;
padding: 0 12px;
color: #ddd;
cursor: pointer;
}
.button:hover {
background: rgba(255, 255, 255, .25)