Skip to content

Instantly share code, notes, and snippets.

@muneneevans
muneneevans / domains.txt
Last active November 4, 2017 10:07
Example of redux domains
Store:
Users:
actionTypes.js
actions.js
reducers.js
selectors.js
service.js
Posts:
actionTypes.js
actions.js
class JsonPlaceHolderService{
static getPosts(){
const url = 'https://jsonplaceholder.typicode.com/posts'
//define my request
const request = {
method: "GET",
};
//make the call and return a json object of the response
return fetch(url, request)
@muneneevans
muneneevans / actionTypes.js
Created November 4, 2017 10:00
action types
export const POSTS_REQUESTED = 'posts.POSTS_REQUESTED'
export const POSTS_RECEIVED = 'posts.POSTS_RECEIVED'
@muneneevans
muneneevans / actions.js
Created November 4, 2017 10:06
action creators. They will make redux dispatches using thunks
import * as types from "./actionTypes"
import JsonPlaceHolderService from "./service"
export function fetchPosts(){
return function(dispatch, getState){
//dispatch an action to show the starte
dispatch({type: types.POSTS_REQUESTED})
return JsonPlaceHolderService.getPosts()
.then(posts =>{
dispatch({
@muneneevans
muneneevans / reducer.js
Created November 4, 2017 10:13
Reducer to handle created actions
import * as types from "./actionTypes"
import Immutable from "seamless-immutable"
const initialState = Immutable({
posts: undefined,
postsIsFetched: false
})
@muneneevans
muneneevans / selectors.js
Created November 4, 2017 10:17
Selectors manipulate and provide data to the user interface
export function getPosts(state){
return state.postsReducer.posts
}
export function getPostStatus(state){
return state.postsReducer.postsIsFetched
}
@muneneevans
muneneevans / PostScreen.js
Created November 4, 2017 12:45
container
import { connect } from 'react-redux'
import React, { Component } from "react"
import { bindActionCreators } from "redux"
//import actions and selectors from the Store folder
import * as postActions from "../Store/Posts/actions"
import * as postSelectors from "../Store/Posts/selectors"
//import your component
import PostItem from "../Components/PostItem"
@muneneevans
muneneevans / cloudSettings
Last active March 8, 2021 16:19
Setting sync
{"lastUpload":"2021-03-08T16:19:35.628Z","extensionVersion":"v3.4.3"}
import { render } from "react-dom"
import React from "react"
import { Provider } from "react-redux"
import { combineReducers, createStore, applyMiddleware } from "redux"
import thunk from 'redux-thunk'
//import the post screen
import PostScreen from "Containers/PostScreen"
@muneneevans
muneneevans / utils.js
Last active September 30, 2019 08:04
Verify basic properties#
export const isNull = value => {
return value === null;
};
export const isUndefined = value => {
return typeof value === "undefined";
};
export const isString = value => {
return typeof value === "string" || value instanceof String;
};
export const isNumber = value => {