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的更多相关文章

  1. [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 ...

  2. Beginning Scala study note(4) Functional Programming in Scala

    1. Functional programming treats computation as the evaluation of mathematical and avoids state and ...

  3. [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 ...

  4. [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 ...

  5. [Functional Programming ADT] Combine Multiple State ADT Based Redux Reducers

    Redux provides a convenient helper for combining many reducers called combineReducer, but it focuses ...

  6. [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 ...

  7. [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 ...

  8. [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 ...

  9. [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 ...

随机推荐

  1. 设置loadrunner中每个mdrv.exe进程中包含的vuser个数

    设置loadrunner中每个mdrv.exe进程中包含的vuser个数 在loadrunner中,默认的是每50个vuser会使用一个mdrv.exe进程,但是有些时候vuser中的使用的线程太多就 ...

  2. EL表达式无法显示Model中的数据

    后台程序通过Debug都能正常返回数据并封装到Model中.而在前台通过EL表达式取值时却是原样输出,如${cart.num}... ///展现我的购物车 @RequestMapping(" ...

  3. 【JavaScript】setinterval和setTimeout的区别

    计时器setTimeout()与setInterval()是原生JS很重要且用处很多的两个方法, 但很多人一直误以为是相同的功能: 间隔时间重复执行传入的句柄函数. 但实际上, 并非如此, 既然JS给 ...

  4. Java GlassPane进度条遮罩

    package com.swing.demo; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Flo ...

  5. JavaScript的程序构成

    JavaScript的程序构成主要从以下几方面做个总结:控制语句.函数 .事件驱动及事件处理,希望对读者有些帮助. 控制语句: if条件语句 基本格式 if(表述式) 语句段1: ...... els ...

  6. 【贪心】【堆】Gym - 101128C - Canvas Painting

    一些画布,每块有其大小,一开始都是白的,你任意将它们排序,然后一次操作可以选择一段连续的相同颜色的画布,从中任选一个位置,左侧涂上任意一种颜色,右侧涂上另一种.消耗是这一段画布的总的大小.问你要将所有 ...

  7. 乐观锁悲观锁对应的JAVA代码和数据库

    乐观锁悲观锁是一种思想.可以用在很多方面. 比如数据库方面.悲观锁就是for update乐观锁就是 version字段 JDK方面:悲观锁就是sync乐观锁就是原子类(内部使用CAS实现) 本质来说 ...

  8. TSQLTableJSON解析JSON

    TSQLTableJSON解析JSON uses mormot rocedure TTestTableContent.SynopseTableVariant;var json: RawUTF8; pe ...

  9. 【redis】2.redis可视化工具安装使用

    redis可视化工具:Redis Desktop Manager 1.redis桌面管理工具[可视化工具]下载 下载地址:https://redisdesktop.com/download 2.点击安 ...

  10. 【maven】maven项目移除Maven Dependencies后如何再添加进去

    比较着急这几天弄一个项目,所以匆忙间把maven项目的Maven Dependencies给remove掉了 如下图: 这下可好,整个项目报错了 解决方法: 对比了有Maven Dependencie ...