bobflux-monitor
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -40,2 +40,3 @@ import * as b from 'bobril'; | ||
stateStamps: IStateStamp[]; | ||
playToggled: (value: boolean) => void; | ||
} | ||
@@ -48,2 +49,3 @@ | ||
interval: number; | ||
isPlaying: boolean; | ||
} | ||
@@ -60,2 +62,3 @@ | ||
ctx.interval = 500; | ||
ctx.isPlaying = false; | ||
}, | ||
@@ -127,3 +130,3 @@ render(ctx: ICtx, me: b.IBobrilNode) { | ||
title: 'PLAY', | ||
isDisabled: !ctx.data.stateStamps.length, | ||
isDisabled: !ctx.data.stateStamps.length || ctx.isPlaying, | ||
onClick: () => { play(ctx, cursor); } | ||
@@ -164,15 +167,22 @@ }), | ||
function play<TState extends f.IState>(ctx: ICtx, cursor: f.ICursor<TState>, isStart = true) { | ||
const state = f.getState(cursor); | ||
let currentIdx = ctx.data.stateStamps.map(stamp => stamp.state).indexOf(state); | ||
if (currentIdx === ctx.data.stateStamps.length - 1 && isStart) { | ||
currentIdx = -1; | ||
function play<TState extends f.IState>(ctx: ICtx, cursor: f.ICursor<TState>, startIndex = -1) { | ||
if (startIndex === -1) { | ||
ctx.isPlaying = true; | ||
ctx.data.playToggled(true); | ||
const state = f.getState(cursor); | ||
startIndex = ctx.data.stateStamps.map(stamp => stamp.state).indexOf(state); | ||
if (startIndex === ctx.data.stateStamps.length - 1) { | ||
startIndex = -1; | ||
} | ||
} | ||
if (currentIdx < ctx.data.stateStamps.length - 1) { | ||
f.setState(cursor, ctx.data.stateStamps[currentIdx + 1].state); | ||
if (startIndex < ctx.data.stateStamps.length - 1) { | ||
const newIndex = startIndex + 1; | ||
f.setState(cursor, ctx.data.stateStamps[newIndex].state); | ||
b.invalidate(); | ||
setTimeout(() => play(ctx, cursor, false), ctx.interval); | ||
setTimeout(() => play(ctx, cursor, newIndex), ctx.interval); | ||
} else { | ||
ctx.isPlaying = false; | ||
ctx.data.playToggled(false); | ||
} | ||
} |
22
index.ts
@@ -5,9 +5,2 @@ import * as b from 'bobril'; | ||
function createDefaultData(): IMonitorPanelData { | ||
return { | ||
isOpen: false, | ||
stateStamps: [] | ||
}; | ||
} | ||
function createStateStamp<TState extends f.IState>(state: TState) { | ||
@@ -22,9 +15,18 @@ return { | ||
// TODO: update fun-model to recognize calling action from stack | ||
// TODO: update fun-model to recognize the calling action from stack | ||
export function init<TState extends f.IState>(cursor: f.ICursor<TState> = { key: '' }): (m, p) => void { | ||
const createMonitor = monitorGenericFactory(cursor); | ||
const data = createDefaultData(); | ||
let routeUrl = ''; | ||
let isPlaying = false; | ||
const data: IMonitorPanelData = { | ||
isOpen: false, | ||
stateStamps: [], | ||
playToggled: (newIsPlaying) => isPlaying = newIsPlaying | ||
}; | ||
const callback = (m, p) => { | ||
if (isPlaying) | ||
return; | ||
if (m && m.indexOf('has been initialized') >= 0) { | ||
@@ -31,0 +33,0 @@ data.stateStamps = [createStateStamp(f.getState(cursor))]; |
{ | ||
"name": "bobflux-monitor", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Component for time travelling in bobflux/fun-model application state history.", | ||
@@ -5,0 +5,0 @@ "typescript": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
25153
668
0