Skip to content

Instantly share code, notes, and snippets.

View panvourtsis's full-sized avatar

Panagiotis Vourtsis panvourtsis

View GitHub Profile
import { from, of } from 'rxjs';
import { catchError, mergeMap, switchMap } from 'rxjs/operators';
const exampleEpic = action$ =>
action$.pipe(
ofType(types.ACTION_REQUEST),
switchMap(({ payload }) =>
from(api.get(payload.data)).pipe(
mergeMap(response =>
of(
import { from, of, concat } from 'rxjs';
import { catchError, mergeMap, switchMap } from 'rxjs/operators';
const exampleEpic = action$ =>
action$.pipe(
ofType(types.ACTION_REQUEST),
switchMap(({ payload }) =>
concat(
of(loadingList()), // Here we define the loading action for our list
from(api.get(payload.data)).pipe(
import { from, of, concat } from 'rxjs';
import { catchError, mergeMap, switchMap } from 'rxjs/operators';
import { startSubmit, stopSubmit } from 'redux-form';
const exampleEpic = action$ =>
action$.pipe(
ofType(types.ACTION_REQUEST),
switchMap(({ payload, meta }) => // yes, meta!
concat(
of(startSubmit(meta.formName)), // Here we define that this specific form is submitting
import { ActionsObservable, StateObservable } from 'redux-observable';
...
it('expects to work perfectly', async () => {
const mockedResponse = {};
const action$ = ActionsObservable.of(action.actionRequest());
const expected = [
addDataAction(mockedResponse), // action 1
pushInfoSnackbar('created successfully') // action 2
];
import { ActionsObservable, StateObservable } from 'redux-observable';
...
it('expects to NOT work perfectly', async () => {
const action$ = ActionsObservable.of(action.actionRequest());
const expected = [
of(pushWarningSnackbar('Failed to create shareable folder')); // failed action
];
mockAxios.onGet().reply(400, null);
import { from, of, concat } from 'rxjs';
import { catchError, mergeMap, switchMap, takeUntil } from 'rxjs/operators';
import { startSubmit, stopSubmit } from 'redux-form';
const exampleEpic = action$ =>
action$.pipe(
ofType(types.ACTION_REQUEST),
switchMap(({ payload, meta }) => // yes, meta!
concat(
of(startSubmit(meta.formName)), // Here we define that this specific form is submitting
@panvourtsis
panvourtsis / panResponderExample.js
Last active June 12, 2019 09:36
RN-PanResponser
import React from 'react';
import { Animated } from 'react-native';
const PanExample = () => {
const panResponder = PanResponder.create({
onStartShouldSetPanResponder: () => true, // we are enabling pan responder on start with this. So now we can listen tap and move
onPanResponderMove: (evt, gestureState) => {
// here we are listening every move
// evt and gestureState simply returns the x,y of the movement position
console.log('yes we are moving', gestureState.dy, gestureState.dx);
import {
SET_USER_TOKEN,
SetUserTokenAction,
} from './types';
import { simpleAction } from '../utils';
export const setUserToken = (token: string): SetUserTokenAction =>
simpleAction(SET_USER_TOKEN, token);
export const SET_USER_TOKEN = 'SET_USER_TOKEN';
export interface SetUserTokenAction {
type: typeof SET_USER_TOKEN;
payload: string;
}
export type UserActionTypes =
| SetUserTokenAction
| ActionB // other action
import { SET_USER, SET_USER_TOKEN, UNSET_USER, UserActionTypes } from './types';
import { User } from './types';
const initialState: User = {
id: null,
name: '',
email: '',
};
function userInfo(state = initialState, action: UserActionTypes): User {