angular - Redux:獲取觸發的動作列表
我在我的 Angular 專案中使用 Redux 來獲取資料到 state 並進行一些 API 呼叫等等。我注意到 Redux 開發工具有列出所有已執行的 actions。有沒有辦法在我的 Angular 應用程式中取得已觸發的 actions 列表?
我想將操作列表發送到後端,並進一步處理它們。
有辦法做到這個嗎?
答案#1
我過去的做法是為 store 創建一個日誌中介軟體。這裡有一個不錯的例子。https://github.com/Webiks/angular-redux-middleware-example
本質上它捕捉了所有動作,你要麼根據這些動作對它們做些什麼,要麼返回下一個函數讓存儲繼續
export function loggerMiddleware(store) {
return function (next) {
return function (action) {
// log a fancy message and action
console.log('Hello, this is your captain speaking.', action);
// continue to the next action
return next(action);
};
};
}
這也可以改寫成如下的形式,只是為了簡化內容:
export const loggerMiddleware = store => next => action {
// log a fancy message and action
console.log('Hello, this is your captain speaking.', action);
// continue to the next action
return next(action);
};
};
}
答案#2
這是一個在 30 秒內把它們弄出來的超級土法方法。它有很多假設,但對你可能有效。
https://reergymerej.github.io/blog/2019/06/14/janky-event-exports.html
- 在控制台輸入
__REDUX_DEVTOOLS_EXTENSION__。 - 雙擊以在虛擬機中打開來源。
- 美化列印。
- 斷點:356。
- 回到工具並跳到一個動作。這應該會觸發你的斷點。
Object.keys(t.actionsById).forEach((id) =>
console.log(t["actionsById"][id].action.type))
