minor tweaking, docs and notes...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-02-07 14:15:43 +03:00
parent 33d4b2ec12
commit f3f6c820db
2 changed files with 47 additions and 37 deletions

View File

@ -1933,17 +1933,17 @@ module.Timers = ImageGridFeatures.Feature({
//
//
// XXX need a mechanism to store the journal in sync (localStorage/fs)
// and be able to execute the journal from last save position if
// recovering from close/crash...
// XXX should this be a separate feature???
//
// XXX would be great to add a mechanism define how to reverse actions...
// ...one way to do this at this point is to revert to last state
// and re-run the journal until the desired event...
// XXX need to define a clear journaling strategy in the lines of:
// - save state clears journal and adds a state load action
// - .load(..) clears journal
// XXX need a way to store additional info in the journal...
// can either be done as:
// - a hook (action handler and/or attr)
// - inline code inside the action...
// can't say I like #2 as it will mess the code up...
// XXX needs careful testing...
var JournalActions = actions.Actions({
@ -1952,37 +1952,17 @@ var JournalActions = actions.Actions({
res.rjournal = null
res.journal = null
if(full && this.hasOwnProperty('journal') && this.journal){
res.journal = JSON.parse(JSON.stringify(this.journal))
}
}
}],
res.journal = JSON.parse(JSON.stringify(this.journal)) } } }],
// Format:
// [
// {
// type: 'basic' | ...,
//
// action: <action-name>,
// args: [ ... ],
//
// // the current image before the action...
// current: undefined | <gid>
//
// // the target (current) image after action...
// target: undefined | <gid>
//
// // additional data, can be set via:
// // <action>.getUndoState(<data>)...
// ...
// },
// ...
// ]
//
// for format docs see: .updateJournalableActions(..)
journal: null,
rjournal: null,
journalable: null,
// XXX docs...
// XXX <action>.getUndoState(..) should be called for every action
// in chain...
// XXX should aliases support explicit undo??? (test)
updateJournalableActions: ['System/Update list of journalable actions',
doc`
@ -1992,6 +1972,32 @@ var JournalActions = actions.Actions({
handlers and add new ones.
NOTE: action aliases can not handle undo.
.journal / .rjournal format:
[
// journaled action..
{
type: 'basic' | ...,
date: <timestamp>,
action: <action-name>,
args: [ ... ],
// the current image before the action...
current: undefined | <gid>
// the target (current) image after action...
target: undefined | <gid>
// additional data, can be set via:
// <action>.getUndoState(<data>)...
...
},
...
]
NOTE: newer journal items are pushed to the .journal tail...
`,
function(){
var that = this
@ -2000,8 +2006,11 @@ var JournalActions = actions.Actions({
return function(){
var data = {
type: 'basic',
date: Date.now(),
action: action,
args: [...arguments],
current: this.current,
// NOTE: we set this after the action is done...
target: undefined,
@ -2023,6 +2032,7 @@ var JournalActions = actions.Actions({
return function(){
data.target = this.current
// prep to get additional undo state...
// XXX this should be called for all actions in chain...
var update = _getActionMethod(action, 'getUndoState')
update
&& update instanceof Function

View File

@ -1,12 +1,12 @@
{
"name": "ImageGrid.Viewer.g4",
"version": "4.0.2a",
"version": "4.0.3a",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "ImageGrid.Viewer.g4",
"version": "4.0.2a",
"version": "4.0.3a",
"dependencies": {
"app-module-path": "^1.0.6",
"async-json": "0.0.2",