[AngularJS NG-redux] Integrate Redux Devtools
In this lesson, we are going to learn how to integrate Redux Devtools into our Angular application.
Redux Devtools is a live-editing time travel environment for Redux. Devtools boasts a list of awesome features but my two favorite ones are that we can inspect every state and action as it happens and we can go back in time by “cancelling” actions.
This is going to be an interesting lesson because, in order for this to work, we are going to need to make something that was written for React work in Angular. For the most part, everything will play side by side with one small trick that we will pull off at the end to force an Angular digest cycle when React manipulates the application store.
Install:
npm install --save-dev bable-preset-react
npm install --save react react-dom redux-devtools redux-devtools-dock-monitor redux-devtools-log-monitor
app.js:
Import:
import React, {Component} from 'react';
import ReactDom from 'react-dom';
import {createDevTools} from 'redux-devtools';
import LogMonitor from 'redux-devtools-log-monitor';
import DockMonitor from 'redux-devtools-dock-monitor';
const DevTools = createDevTools(
<DockMonitor toggleVisibilityKey='ctrl-h'
changePositionKey='ctrl-q'
defaultIsVisible={false}>
<LogMonitor theme='tomorrow' />
</DockMonitor>
); const run = ($ngRedux, $rootScope) => {
'ngInject'; const componentDidUpdate = DockMonitor.prototype.componentDidUpdate;
DockMonitor.prototype.componentDidUpdate = function() {
$rootScope.$evalAsync();
if (componentDidUpdate) {
return componentDidUpdate.apply(this, arguments);
}
}; ReactDom.render(
<DevTools store={$ngRedux}/>,
document.getElementById('devTools')
);
}; const config = $ngReduxProvider => {
'ngInject';
$ngReduxProvider.createStoreWith(rootReducers, [thunk], [DevTools.instrument()]);
};
Open devtools:
ctrl + h
import 'bootstrap-css-only';
import 'normalize.css'; import angular from 'angular';
import CommonModule from './common/common';
import ComponentsModule from './components/components';
import thunk from 'redux-thunk';
import template from './app.html';
import './app.css'; import React, {Component} from 'react';
import ReactDom from 'react-dom';
import {createDevTools} from 'redux-devtools';
import LogMonitor from 'redux-devtools-log-monitor';
import DockMonitor from 'redux-devtools-dock-monitor'; import { categories, CategoriesActions, category } from './components/categories/category.state';
import { bookmarks, BookmarksActions, bookmark } from './components/bookmarks/bookmarks.state';
import ngRedux from 'ng-redux';
import { combineReducers } from 'redux';
const rootReducers = combineReducers({
categories,
category,
bookmarks,
bookmark
}); const DevTools = createDevTools(
<DockMonitor toggleVisibilityKey='ctrl-h'
changePositionKey='ctrl-q'
defaultIsVisible={false}>
<LogMonitor theme='tomorrow' />
</DockMonitor>
); const run = ($ngRedux, $rootScope) => {
'ngInject'; const componentDidUpdate = DockMonitor.prototype.componentDidUpdate;
DockMonitor.prototype.componentDidUpdate = function() {
$rootScope.$evalAsync();
if (componentDidUpdate) {
return componentDidUpdate.apply(this, arguments);
}
}; ReactDom.render(
<DevTools store={$ngRedux}/>,
document.getElementById('devTools')
);
}; const config = $ngReduxProvider => {
'ngInject';
$ngReduxProvider.createStoreWith(rootReducers, [thunk], [DevTools.instrument()]);
}; const AppComponent = {
template
}; let appModule = angular.module('app', [
CommonModule.name,
ComponentsModule.name,
ngRedux
])
.config(config)
.run(run)
//.value('store', store)
.factory('CategoriesActions', CategoriesActions)
.factory('BookmarksActions', BookmarksActions)
.component('app', AppComponent); export default appModule;
[AngularJS NG-redux] Integrate Redux Devtools的更多相关文章
- React-安装和配置redux调试工具Redux DevTools
chrome扩展程序里搜索Redux DevTools进行安装 新建store的时候,进行如下配置. import { createStore, applyMiddleware ,compose} f ...
- [PReact] Integrate Redux with Preact
Redux is one of the most popular state-management libraries and although not specific to React, it i ...
- [AngularJS] Write a simple Redux store in AngularJS app
The first things we need to do is create a reducer: /** * CONSTANT * @type {string} */ export const ...
- 25.redux回顾,redux中的action函数异步
回顾:Redux: 类似于 Vuex 概念:store/reducer/action action:动作 {type,.....} 一定要有type 其他属性不做限制 reducer:通过计算产生st ...
- Redux 和 Redux thunk 理解
1: state 就像 model { todos: [{ text: 'Eat food', completed: true }, { text: 'Exercise', completed: fa ...
- [Redux] Understand Redux Higher Order Reducers
Higher Order Reducers are simple reducer factories, that take a reducer as an argument and return a ...
- 手把手教你撸一套Redux(Redux源码解读)
Redux 版本:3.7.2 Redux 是 JavaScript 状态容器,提供可预测化的状态管理. 说白了Redux就是一个数据存储工具,所以数据基础模型有get方法,set方法以及数据改变后通知 ...
- 记一次修改框架源码的经历,修改redux使得redux 可以一次处理多个action,并且只发出一次订阅消息
redux是一个数据状态管理的js框架,redux把行为抽象成一个对象,把状态抽象成一个很大的数据结构,每次用户或者其他什么方式需要改变页面都可以理解成对数据状态的改变,根据出发这次改变的不同从而有各 ...
- Part 6 AngularJS ng repeat directive
ng-repeat is similar to foreach loop in C#. Let us understand this with an example. Here is what we ...
随机推荐
- command---调用指定的指令并执行
command命令调用指定的指令并执行,命令执行时不查询shell函数.command命令只能够执行shell内部的命令. 语法 command(参数) 参数 指令:需要调用的指令及参数. 实例 使用 ...
- 洛谷——P1311 选择客栈
https://www.luogu.org/problem/show?pid=1311 题目描述 丽江河边有n 家很有特色的客栈,客栈按照其位置顺序从 1 到n 编号.每家客栈都按照某一种色调进行装饰 ...
- [Docker 官方文档] 理解 Docker
http://segmentfault.com/a/1190000002609286 什么是 Docker? Docker 是一个用于开发.交付和执行应用的开放平台,Docker 设计用来更快的交付你 ...
- Go语言核心之美 1.5-作用域
变量的作用域是指程序代码中能够有效使用这个变量的范围. 不要将作用域和生命期混在一起. 作用域是代码中的一块区域,是一个编译期的属性:生命期是程序执行期间变量存活的时间段.在此时间段内,变量能够被程序 ...
- socket 笔记(一)
#include "stdafx.h" #include "WINSOCK2.H" #pragma comment(lib,"WS2_32.lib&q ...
- robot framework 使用三:浏览器兼容性自己主动化
robot framework 測试浏览器兼容性 上图中黄色圈的地方默认什么都不写.是firefox浏览器,写上ie就是ie浏览器了 firefox最新版本号即可.ie须要设置: 1. IE选项设置的 ...
- gogodroid--android 上的IPV6工具
gogodroid--android 上的IPV6工具 系统需求是 Android 1.6以上的系统,已经root,能够执行modprobe命令(在终端里输入modprobe,如果显示了帮助便可以), ...
- 1.1 Introduction中 Kafka for Stream Processing官网剖析(博主推荐)
不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Kafka for Stream Processing kafka的流处理 It i ...
- python一切皆对象的理解
min_error=pls(x_train, x_test, y_train, y_test) #这里我之前写的是error,但是前面有一个定义的error函数.所以导致出现了警告. 可能是因为pyt ...
- Linux学习总结(4)——Centos6.5使用yum安装mysql——快速上手必备
第1步.yum安装mysql [root@stonex ~]# yum -y install mysql-server 安装结果: Installed: mysql-server.x86_6 ...