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... // 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 // ...one way to do this at this point is to revert to last state
// and re-run the journal until the desired event... // and re-run the journal until the desired event...
// XXX need to define a clear journaling strategy in the lines of: // XXX need to define a clear journaling strategy in the lines of:
// - save state clears journal and adds a state load action // - save state clears journal and adds a state load action
// - .load(..) clears journal // - .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... // XXX needs careful testing...
var JournalActions = actions.Actions({ var JournalActions = actions.Actions({
@ -1952,37 +1952,17 @@ var JournalActions = actions.Actions({
res.rjournal = null res.rjournal = null
res.journal = null res.journal = null
if(full && this.hasOwnProperty('journal') && this.journal){ if(full && this.hasOwnProperty('journal') && this.journal){
res.journal = JSON.parse(JSON.stringify(this.journal)) res.journal = JSON.parse(JSON.stringify(this.journal)) } } }],
}
}
}],
// Format: // for format docs see: .updateJournalableActions(..)
// [
// {
// 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>)...
// ...
// },
// ...
// ]
//
journal: null, journal: null,
rjournal: null, rjournal: null,
journalable: null, journalable: null,
// XXX docs...
// XXX <action>.getUndoState(..) should be called for every action
// in chain...
// XXX should aliases support explicit undo??? (test) // XXX should aliases support explicit undo??? (test)
updateJournalableActions: ['System/Update list of journalable actions', updateJournalableActions: ['System/Update list of journalable actions',
doc` doc`
@ -1992,6 +1972,32 @@ var JournalActions = actions.Actions({
handlers and add new ones. handlers and add new ones.
NOTE: action aliases can not handle undo. 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(){ function(){
var that = this var that = this
@ -2000,8 +2006,11 @@ var JournalActions = actions.Actions({
return function(){ return function(){
var data = { var data = {
type: 'basic', type: 'basic',
date: Date.now(),
action: action, action: action,
args: [...arguments], args: [...arguments],
current: this.current, current: this.current,
// NOTE: we set this after the action is done... // NOTE: we set this after the action is done...
target: undefined, target: undefined,
@ -2023,6 +2032,7 @@ var JournalActions = actions.Actions({
return function(){ return function(){
data.target = this.current data.target = this.current
// prep to get additional undo state... // prep to get additional undo state...
// XXX this should be called for all actions in chain...
var update = _getActionMethod(action, 'getUndoState') var update = _getActionMethod(action, 'getUndoState')
update update
&& update instanceof Function && update instanceof Function

View File

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