[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 ...
随机推荐
- docker集群
http://blog.csdn.net/zhaoguoguang/article/details/51161957
- 关于render函数的总结
一般情况下封装一个导航组件的写法 <!DOCTYPE html> <html lang="en"> <head> <meta charse ...
- 洛谷——P2784 化学1(chem1)- 化学合成
P2784 化学1(chem1)- 化学合成 题目背景 蒟蒻HansBug在化学考场上,挠了无数次的头,可脑子里还是一片空白. 题目描述 眼下出现在蒟蒻HansBug面前的是一个化学合成题,据他所知, ...
- HDU 6119 2017百度之星初赛B 小小粉丝度度熊 (二分)
小小粉丝度度熊 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- 第8天-setInterval/setTimeout
setInterval是什么? setInterval()方法重复调用一个函数或执行一个代码段,在每次调用之间具有固定的时间延迟. setInterval(函数,间隔时间) 例如 function f ...
- C++中template的.h文件和.cpp文件的问题
在C++中,用到类模板时,如果类似一般的类声明定义一样,把类声明放在.h文件中,而具体的函数定义放在.cpp文件中的话,会发现编译器会报错.如类似下面代码: //test.h文件 #ifndef TE ...
- Python的zip函数(转)
原文地址:http://www.cnblogs.com/frydsh/archive/2012/07/10/2585370.html zip函数接受任意多个(包括0个和1个)序列作为参数,返回一个tu ...
- [BZOJ4455][ZJOI2016]数星星(容斥DP)
4455: [Zjoi2016]小星星 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 707 Solved: 419[Submit][Status] ...
- [BZOJ4818][SDOI2017]序列计数(动规+快速幂)
4818: [Sdoi2017]序列计数 Time Limit: 30 Sec Memory Limit: 128 MBSubmit: 972 Solved: 581[Submit][Status ...
- SD 一轮集训 day4 弦形袋鼠
可以发现把每一个 a[i] * b[i] 加到矩阵里去,就相当于 把一个 1*m 的向量伸缩后变成 n个再加到矩阵里去,所以答案就是远=原矩阵中线性线性无关组的个数. (而且好像一个矩阵横着消元和竖着 ...