[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 ...
随机推荐
- C_深入(内存模型)
01 数据类型: 为什么有数据类型? 现实生活中的数据太多而且大小形态不一. 数据类型与内存的关系: 数据类型的本质:创建变量的模具,是固定大小的别名. #include "stdio.h& ...
- wordpress+wampserver
听说过wordpress和joomla这样的简单建站的工具,尽管是PHP,可是看过同事搭建的公司站点.效果真心不错.于是手痒痒尝试一下.由于是搭着玩儿.所以用wordpress+wampserver( ...
- 10款jQuery/CSS3动画应用 超有用
http://www.html5tricks.com/10-jquery-css3-animation.html
- [Docker 官方文档] 理解 Docker
http://segmentfault.com/a/1190000002609286 什么是 Docker? Docker 是一个用于开发.交付和执行应用的开放平台,Docker 设计用来更快的交付你 ...
- 通过OpenSSL解析X509证书基本项
在之前的文章"通过OpenSSL解码X509证书文件"里.讲述了怎样使用OpenSSL将证书文件解码,得到证书上下文结构体X509的方法. 以下我们接着讲述怎样通过证书上下文结构体 ...
- 新技能 get —— 如何校验 md5(windows)
我们在某资源网站上下载完成指定文件后,尤其是一些下载所需较高时长的大型文件,如何检验下载的文件是否完好,也即如何保证和原始网站上的资源一样.此时就要用到检验码的机制,一般文件的下载界面,通常都会给出此 ...
- jQuery自定义插件规范
<ul class="list"> <li>导航列表 <ul class="nav"> <li>导航列表1< ...
- ASP.NET MVC 4 (十一) Bundles和显示模式--asp.net mvc中 @Scripts.Render("~/bundles/jquery")是什么意思? 在布局文件中使用Scripts.Render()输出脚本包,Styles.Render()输出风格包:
ASP.NET MVC 4 (十一) Bundles和显示模式 ASP.NET MVC 4 引入的js打包压缩功能.打包压缩jquery目录下的文件,在布局文件中使用Scripts.Render()输 ...
- python绘图问题
论文绘图整理 # coding: utf-8 #来源:https://blog.csdn.net/A_Z666666/article/details/81165123 import matplotli ...
- Vue的学习--环境配置
1. 下载vue.min.js或者使用CDN 2. 安装Vue-cli环境 我在window7 32位下使用命令行cmd进行的操作 安装之前应该使用node -v和npm -v检查一下node和n ...