Skip to content

Instantly share code, notes, and snippets.

@dzNavitski
dzNavitski / cancel-on-contect.js
Created April 30, 2017 17:48
cancel depend on context
const fetchUserEpic = action$ =>
action$.ofType(FETCH_USER)
.mergeMap(action => {
var date = Date.now();
console.log(date)
return fakeAjax(`/api/users/${action.payload}`)
.map(response => fetchUserFulfilled(response))
.takeUntil(
action$.
ofType(FETCH_USER_CANCELLED)
@dzNavitski
dzNavitski / AutoSavingForm.md
Created May 2, 2017 09:06 — forked from oyeanuj/AutoSavingForm.md
Auto-saving forms using Redux-Form

Here is how I ended up making this work. For more context and background on the discussion, I recommend reading conversation in ReduxForm#2169 (and chiming in with your learnings, etc).

So, as per the conversation there, I tried the 'many little forms' approach. I am sharing both my approach, and a crude abstracted out gist that can hopefully help out y'all.

Essentially, with this approach:

  1. You want to use each field as a little form which submits debounced onChange.
  2. For each field as a little form, you want to abstract that into a component which can be provided an input, as much as possible.
  3. Set autofocus for the first form.
  4. For debounced onChange, I used react-debounced-input.
import Joi from 'joi-full';
const schema = Joi.object().keys({
postTitle: Joi.string()
.required()
.min(3)
.options({
language: {
any: {
empty: '{{key}} is required',
const editEpic = (action$, store) => action$
.ofType(t.EDIT_UPDATE)
.debounceTime(100)
.mergeMap((action) => {
const { path } = action.meta;
return validate$()
.delay(3000)
.map(() => modelActions.modelSetPendingValidation({ value: false, path: path }))
.takeUntil(
const uploadDocumentEpic = action$ =>
action$.ofType(UPLOAD_DOCUMENT).switchMap(action => {
const {id, data} = action.payload
const sub = new Subject()
const requester = Observable.fromPromise(
axios({
url: 'https://api.foo.com',
data: {
file: data
},
export const apiValidate = action$ => {
return action$.ofType(validateRequestAction)
.debounceTime(250)
.switchMap((action) => (
Observable.ajax({
url: url,
method: 'GET',
crossDomain: true,
headers: {
"Content-Type": 'application/json'
@dzNavitski
dzNavitski / disableBodyScroll.js
Created September 8, 2017 18:00 — forked from thuijssoon/disableBodyScroll.js
iOS disable body scroll
/**
* Prevent body scroll and overscroll.
* Tested on mac, iOS chrome / Safari, Android Chrome.
*
* Based on: https://benfrain.com/preventing-body-scroll-for-modals-in-ios/
* https://stackoverflow.com/a/41601290
*
* Use in combination with:
* html, body {overflow: hidden;}
*
@dzNavitski
dzNavitski / .eslintrc.js
Created October 25, 2017 03:53 — forked from nikgraf/.eslintrc.js
Prettier / Eslint Setup
module.exports = {
root: true, // make to not take in any user specified rules in parent folders
parser: 'babel-eslint',
extends: ['airbnb', 'prettier', 'prettier/flowtype', 'prettier/react'],
env: {
browser: true,
node: true,
jest: true,
},
plugins: ['react', 'import', 'flowtype'],

NGRX Data

A higher-order service abstraction for NGRX. It eliminates the boilerplate for CRUD operations with lists.

provideStore({ pizza: entityReducer('pizza') })

const entity = thie.entityService<Pizza>('pizza', this.pizzaService);
entity.query();

const collection$ = this.store.select(state =&gt; state.pizza.collection);
@dzNavitski
dzNavitski / combineContext.js
Created March 29, 2018 05:13 — forked from etienne-dldc/combineContext.js
A small function to combine react Contexts.
import React from 'react';
function onlyChild(children) {
return Array.isArray(children) ? children[0] : children;
}
export function combineContext(contexts) {
class Provider extends React.Component {
render() {
const init = this.props.children;