This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "items": { | |
| "1234": { | |
| "id": 1, | |
| "name": "John Doe" | |
| }, | |
| "4321": { | |
| "id": 2, | |
| "name": "Foo Bar" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const createConnectionModel = (config: any, refreshURL: string) => { | |
| const instance = axios.create(config); | |
| let refreshRequest: Promise<any>; | |
| const unauthorized = createEvent(); | |
| /* если юзаете JWT без кук, что впрочем, я не рекомендую | |
| instance.interceptors.request.use((config) => { | |
| config.headers['auth'] = localStorage.getItem(...); | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { createEffect, createEvent, createStore, restore } from "effector"; | |
| export const createWebSocketConnection = (url: string, retries = 5) => { | |
| const onEvent = createEvent<Event>(); | |
| const statusChanged = onEvent.map(({ type }) => type); | |
| const message = createEvent<MessageEvent>(); | |
| const send = createEffect(); | |
| const $status = restore(statusChanged.filter({ fn: (status) => status === "close" || status === "open" }), "close"); | |
| const error = onEvent.filter({fn: ({type}) => type === "error"}) | |
| const retry = createEffect(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { createActions, handleActions, combineActions } from 'redux-actions'; | |
| const defaultState = { counter: 10 }; | |
| const { increment, decrement } = createActions({ | |
| INCREMENT: (amount = 1) => ({ amount }), | |
| DECREMENT: (amount = 1) => ({ amount: -amount }) | |
| }); | |
| const reducer = handleActions( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const createConnectionModel = (config: AxiosRequestConfig, refreshURL: string) => { | |
| const unauthenticated = createEvent(); | |
| let refreshRequest: Promise<any>; | |
| const connection = axios.create(config); | |
| connection.interceptors.response.use(null, async (err) => { | |
| if(err.response.code === 401){ | |
| if(err.response.data === "Unauthenticated"){ | |
| unauthenticated(); | |
| throw new Error("unauthenticated"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { createEffect, createEvent, createStore, Event as EffectorEvent } from "effector"; | |
| export const createWebSocketConnection = (url: string) => { | |
| const instance = new WebSocket(url); | |
| const sendMessage = createEffect<object, any, Error>().use((data) => instance.send(JSON.stringify(data))); | |
| const {message, statusChanged} = createEvents(instance); | |
| const status = createStore<keyof WebSocketEventMap>("close") | |
| .on(statusChanged, (_, e) => e.type) |