Skip to content

Instantly share code, notes, and snippets.

View panvourtsis's full-sized avatar

Panagiotis Vourtsis panvourtsis

View GitHub Profile
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 { 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 { 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 { 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 } 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(
@panvourtsis
panvourtsis / JSMeetupModule.java
Last active January 3, 2019 13:04
JSMeetup Native Module
package com.JSMeetup;
import ...
class JSMeetupModule extends ReactContextBaseJavaModule {
private static String mPremium = "";
public JSMeetupModule(ReactApplicationContext reactContext) {
super(reactContext);
...
@panvourtsis
panvourtsis / FlatArray.js
Created October 17, 2018 07:32
A function that flattens an array
// if an array has content join all parts to comma seperated string and splitted to a new array
const flatArray = (array) => array.length ? array.join().split(',') : [];
flatArray([[1,2,[3]],4])
flatArray([1,2,3,4])
flatArray([1,2,[3,[4,5]],6])
@panvourtsis
panvourtsis / app-sample.js
Created June 9, 2017 18:17
This is a small example of the app.js. The actuall app is going to have more config. You will see some functions missing
import ngRedux from "ng-redux";
import thunk from "redux-thunk";
import {RootReducer} from "./Reducers";
angular
.module(
"funkmartini",
[
...,
ngRedux,
.....
import {combineReducers} from "redux";
import Ratings from "./ratings/RatingsReducer";
// Combine all reducers into one root reducer
export const RootReducer = combineReducers({
Ratings
});
@panvourtsis
panvourtsis / RatingsPage.js
Created June 9, 2017 18:15
high order component
import { connect } from "react-redux";
import React, { Component } from "react";
import PropTypes from "prop-types";
// Import Components
import RatingList from "./components/RatingList/RatingList";
// Import Actions
import { fetchRatings } from "./RatingsActions";
// import Reducer
import { getRatings } from "./RatingsReducer";
class RatingsPage extends Component {