[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;
复制代码

 

posted @   Zhentiw  阅读(390)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2015-11-15 [MongoDB] Introduce to MongoDB
2015-11-15 [Protractor] Getting Started With Protractor
2014-11-15 [Grunt] grunt.template
2014-11-15 [Grunt] Watch && grunt-contrib-watch
2014-11-15 [AngularJS] Angular 1.3 ng-model-options - getterSetter
2014-11-15 [ES6] 01. Intro to ES6 and traceur compiler
点击右上角即可分享
微信分享提示