Skip to content

Commit 66e8b1b

Browse files
committed
Limit actions to be stored. Autocommit when the limit exceeds.
Related to #14.
1 parent 4dd618b commit 66e8b1b

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed

src/app/constants/ActionTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export const ACTION = 'ACTION';
22
export const UPDATE = 'UPDATE';
33
export const OPTIONS = 'OPTIONS';
4+
export const COMMIT = 'COMMIT';

src/browser/extension/inject/pageScript.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import stringify from 'json-stringify-safe';
22
import configureStore from '../../../app/store/configureStore';
3-
import { ACTION, UPDATE, OPTIONS } from '../../../app/constants/ActionTypes';
3+
import { ACTION, UPDATE, OPTIONS, COMMIT } from '../../../app/constants/ActionTypes';
44

55
window.devToolsInit = function(store) {
66
let options = {};
77
let timeout = { id: null, last: 0};
88

99
function doChange(init) {
10-
const state = store.liftedStore.getState();
10+
let state = store.liftedStore.getState();
11+
if (options.limit && state.currentStateIndex > options.limit) {
12+
store.liftedStore.dispatch({type: COMMIT, timestamp: Date.now()});
13+
state = store.liftedStore.getState();
14+
}
1115
window.postMessage({
1216
payload: options.serialize ? stringify(state) : state,
1317
source: 'redux-page',
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
const getOptions = callback => {
22
chrome.storage.sync.get({
3+
limit: 50,
34
timeout: 1,
45
serialize: true,
56
inject: true,
67
urls: 'https?:\\/\\/localhost|0\\.0\\.0\\.0:\\d+\\/(.+)?\nhttps?:\\/\\/.+\\.github\\.io\\/(.+)?'
78
}, function(items) {
8-
callback(items)
9+
callback(items);
910
});
10-
}
11+
};
1112

1213
export default getOptions;

src/browser/extension/options/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ const saveUrls = e => {
3131
getOptions( items => {
3232
render(
3333
<div>
34+
<div className="input">
35+
<span className="caption">Maximum actions:</span>
36+
<input id="limit" type="text" defaultValue={items.limit} onChange={saveOption} />
37+
<span className="comment">(autocommit when exceeds, 0 - no limit)</span>
38+
</div>
3439
<div className="input">
3540
<span className="caption">Maximum delay:</span>
3641
<input id="timeout" type="text" defaultValue={items.timeout} onChange={saveOption} />

src/browser/views/options.jade

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ html
2222
color: #999;
2323
margin-left: 5px;
2424
}
25-
#timeout {
25+
input[type="text"] {
2626
width: 25px;
2727
font-weight: bold;
2828
text-align: center;

0 commit comments

Comments
 (0)