[Functional Programming ADT] Create a Redux Store for Use with a State ADT Based Reducer
With a well defined demarcation point between Redux and our State ADT based model, hooking up to a Redux store is no different than any other Redux based implementation. Once we have all of our transitions represented in dispatchable actions, we can step though a typical game flow and see our hard work pay off.
We will see how to interget redux with our State:
/store.js
// redux store
import { createStore } from "redux";
import { initialState } from "./model/initialize";
import reducer from "./reducers"; export default createStore(reducer, initialState());
index.js
import log from "./logger"; import { startGame, hideAllCards } from "./data/reducers/game"; import { selectCard, showFeedback } from "./data/reducers/turn"; import store from "./data/store"; const { dispatch, getState } = store; log(getState());
/**
{ colors: [ 'orange', 'green', 'blue', 'yellow' ], shapes: [ 'triangle', 'circle', 'square' ], cards: [ ], hint: { }, isCorrect: null, left: 8, moves: 0, rank: 4, seed: 1549885157384 }
*/
It return our initial state.
If we want to dipatch action, we can do:
dispatch(startGame());
/**
* { colors: [ 'orange', 'green', 'blue', 'yellow' ], shapes: [ 'triangle', 'circle', 'square' ], cards: [ { id: 'green-square', color: 'green', shape: 'square', selected: true }, { id: 'yellow-circle', color: 'yellow', shape: 'circle', selected: true }, { id: 'green-circle', color: 'green', shape: 'circle', selected: true }, { id: 'yellow-square', color: 'yellow', shape: 'square', selected: true }, { id: 'blue-circle', color: 'blue', shape: 'circle', selected: true }, { id: 'green-triangle', color: 'green', shape: 'triangle', selected: true }, { id: 'orange-square', color: 'orange', shape: 'square', selected: true }, { id: 'yellow-triangle', color: 'yellow', shape: 'triangle', selected: true }, { id: 'orange-triangle', color: 'orange', shape: 'triangle', selected: true } ], hint: { }, isCorrect: null, left: 8, moves: 0, rank: 4, seed: 270041088 }
*/
[Functional Programming ADT] Create a Redux Store for Use with a State ADT Based Reducer的更多相关文章
- [Functional Programming] Randomly Pull an Item from an Array with the State ADT (Pair)
Functor composition is a powerful concept that arises when we have one Functor nested in another Fun ...
- Beginning Scala study note(4) Functional Programming in Scala
1. Functional programming treats computation as the evaluation of mathematical and avoids state and ...
- [React + Functional Programming ADT] Connect State ADT Based Redux Actions to a React Application
With our Redux implementation lousy with State ADT based reducers, it is time to hook it all up to a ...
- [Functional Programming ADT] Initialize Redux Application State Using The State ADT
Not only will we need to give our initial state to a Redux store, we will also need to be able to re ...
- [Functional Programming ADT] Combine Multiple State ADT Based Redux Reducers
Redux provides a convenient helper for combining many reducers called combineReducer, but it focuses ...
- [Functional Programming ADT] Create State ADT Based Reducers (applyTo, Maybe)
The typical Redux Reducer is function that takes in the previous state and an action and uses a swit ...
- [Functional Programming ADT] Adapt Redux Actions/Reducers for Use with the State ADT
By using the State ADT to define how our application state transitions over time, we clear up the ne ...
- [Functional Programming] Draw Items from One JavaScript Array to Another using a Pair ADT
We want to be able to pick nine random cards from an array of twelve cards, but can run into problem ...
- [Functional Programming] Combine Multiple State ADT Instances with the Same Input (converge(liftA2(constant)))
When combining multiple State ADT instances that depend on the same input, using chain can become qu ...
随机推荐
- H264 帧边界识别简介
http://blog.csdn.net/wzw88486969/article/details/50364017
- RecyclerView 和 ListView 使用对比分析
原文地址:http://blog.coderclock.com/2016/08/08/android/RecyclerView%20%E5%92%8C%20ListView%20%E4%BD%BF%E ...
- (8)go 字符串
内建函数在 包中 1. len(str) 计算长度,中文占3个字符 2.字符串遍历,同时处理中文 package main import ( "fmt" ) func main() ...
- PAT L3-011. 直捣黄龙
最短路. 先求出一个只包含最短路的$DAG$,然后在$DAG$上$dp$一下就可以了.英文变数字还有$map$转一下. #include<map> #include<set> ...
- Python3 文件读写注意事项(指针问题)
C:\Users\Administrator\AppData\Local\Programs\Python\Python35\python.exe E:/python/day2/op.py Someho ...
- Xamarin 中Visual Studio创建项目提示错误
Xamarin 中Visual Studio创建项目提示错误 错误信息:Object reference not set to an instance of an object 出现这种情况,是由于没 ...
- [Codeforces #188] Tutorial
Link: Codeoforces #188 传送门 A: 先全转为正数,后面就全是指数级增长了 #include <bits/stdc++.h> using namespace std; ...
- Eden的退役记
好久没更博客了, 这篇随笔不同于之前的学术性随笔.游记,只是来发泄一下自己的情感,回忆一下自己的OI经历…… 五年的OI生涯结束了 初一:懵懂的我刚接触了OI,被其功能吸引.由于运气好过了初赛,然而复 ...
- centos yum命令报错
Loaded plugins: fastestmirror, security Loading mirror speeds from cached hostfile Could not retriev ...
- [典型漏洞分享]YS的防暴力破解设计存在缺陷
YS使用的防暴力破解机制存在缺陷,该缺陷可被用于暴力破解其它用户密码[高] 问题描述: YS在用户登录页面设置了验证码机制,当用户输入密码错误次数达到3次时,再次登录需要验证码以防止攻击者进行暴力破解 ...