Skip to content

Instantly share code, notes, and snippets.

View Tauka's full-sized avatar
🎯
Focusing

Tauyekel Kunzhol Tauka

🎯
Focusing
  • Nazarbayev University
  • Astana, Kazakhstan
View GitHub Profile
@Tauka
Tauka / basket.js
Created February 9, 2018 12:18 — forked from kana-sama/basket.js
products-basket-selectors-example
// fake reselect
const createSelector = (deps, body) => (state, props) =>
body(...deps.map(dep => dep(state, props)));
const createStructuredSelector = scheme => (state, props) =>
Object.keys(scheme).reduce((result, key) => ({
...result,
[key]: scheme[key](state, props)
}), {});
@Tauka
Tauka / redux-ducks-example.tsx
Created January 21, 2018 10:11
How to structure redux for by-feature grouping
import { createActions, handleActions, combineActions } from "redux-actions";
import { call, put, takeLatest } from "redux-saga/effects";
import { api } from "../../helpers";
import { Root } from "../../redux";
/*
* TYPES
* --------------------------------------------------------------
*/
enum requestStatusEnum {
export default function reducer(state={
data: []
}, action) {
switch(action.type) {
case "ACTION_SUCCESS": {
return {...state, data: action.payload}
}
return state;
}
export function typicalAction(loadingCb, successCb, failCb) {
return function(dispatch) {
loadingCb();
fetch(`http://someapi/user`)
.then((response) => {
dispatch({type: "ACTION_SUCCESS", payload: response});
successCb();
})
import React from "react";
import { connect } from "react-redux";
import { bindActionCreators } from "redux";
import * as actions from "./actions.js";
@connect((store) => {
return {
someStore: store.someStore,
};
},
import React from "react";
import { connect } from "react-redux";
import { bindActionCreators } from "redux";
import * as actions from "./actions.js";
@connect((store) => {
return {
someStore: store.someStore,
};
},
export default function reducer(state={
groups: [],
group: null,
groupsFetchPending: false,
groupsFetchSuccess: null,
groupFetchPending: false,
groupFetchSuccess: null,
groupNewPending: false,
groupNewSuccess: null,
groupNewPending: false,
export default function reducer(state={
data: [],
requestSuccess: false,
requestPending: false,
requestFail: false
}, action) {
switch(action.type) {
case "ACTION_PENDING": {
return {...state, requestPending: true}
}
export function typicalAction() {
return function(dispatch) {
dispatch({type: "ACTION_PENDING"});
fetch(`http://someapi/user`)
.then((response) => {
dispatch({type: "ACTION_SUCCESS", payload: response});
})
.catch((err) => {
dispatch({type: "ACTION_FAIL", payload: err });