Haschanged / changecount reset

26 views
Skip to first unread message

TonyM

unread,
Jul 14, 2020, 1:32:55 AM7/14/20
to TiddlyWikiDev
Folks,

The changecount macro and haschanged mechanism is built on Javascript and forms part of the core. Thus I am asking this question here for coders of JS, and with a deep tiddlywiki understanding.
  • I am wondering if it could be possible to reset the changecount on tiddlers, according to a filter or per tiddler, thus I believe their listing in haschanged will not occur?
  • If possible It would be nice to provide a mechanism where the export process or a custom export button, can be set to do this automatically. Perhaps it needs to be an action widget.
  • The change count can be reset by a save and reload, or a reload and not save (loosing the changes) but this does not help.
  • I am willing to risk the fact the export may not complete, because in part I can leverage local storage, and the export can be re-initiated.

Why;

Current Example: If I am building a package and I export the content say to a json file or plugin package, I would like to reset the change count because this indicates the tiddlers no longer need saving because they have being saved via an export. 

One strong use case it if a user is on a readonly wiki, such as where they do not have a suitable saver or access to save, eg github hosted/php hosted etc.. then they could fill out a survey. Once they export their survey answers, the they are not longer "unsaved" changes, I can reset the dirty indicator and they can leave the site without a warning, until then the dirty indicator will protect them from leaving the site before their changes are saved/exported.

A similar method may be used if the package of tiddlers are sent as an attachment by email (which I am yet to build)

Possible issue
  • I am not sure if the local storage plugin relies on this same mechanism? However this could be a way to clear the dirty indicator for items saved in local storage. 
  • Will this disrupt the save mechanisms?

Thank you for reading this. I would appreciate your help.
Regards
Tony

Eric Shulman

unread,
Jul 14, 2020, 2:38:16 AM7/14/20
to TiddlyWikiDev
On Monday, July 13, 2020 at 10:32:55 PM UTC-7, TonyM wrote:
One strong use case it if a user is on a readonly wiki, such as where they do not have a suitable saver or access to save, eg github hosted/php hosted etc.. then they could fill out a survey. Once they export their survey answers, the they are not longer "unsaved" changes, I can reset the dirty indicator and they can leave the site without a warning, until then the dirty indicator will protect them from leaving the site before their changes are saved/exported.

$:/config/SaverFilter defines a filter that determines whether or not the isDirty flag is set.

When you export tiddlers, you could add those tiddlers to the $:/config/SaverFilter definition, thereby allowing those tiddlers to be ignored when exiting, bypassing the warning.  Of course, you'd also want to add -[[$:/config/SaverFilter]] as well, so that the changes to the filter itself won't trigger the warning on exit.

Add something like this to your custom export button:
\define newItem() -[[$(item)$]]

<$button> custom export
... do your custom export processing ...
<$list filter="... stuff you've just exported... " variable="item">
   <$action-setfield $tiddler="$:/config/SaverFilter" text={{{ [{$:/config/SaverFilter}addsuffix[ ]addsuffix<newItem>] }}} />
</$list>
<$vars item="$:/config/SaverFilter">
   <$action-setfield $tiddler="$:/config/SaverFilter" text={{{ [{$:/config/SaverFilter}addsuffix[ ]addsuffix<newItem>] }}} />
</$vars>

note: untested code

Hopefully this should get you most of the way there...

-e

PMario

unread,
Jul 14, 2020, 2:44:21 AM7/14/20
to tiddly...@googlegroups.com
I don't have the real core code in mind, but as far as I can remember. ....

On Tuesday, July 14, 2020 at 7:32:55 AM UTC+2, TonyM wrote:

Why;

Current Example: If I am building a package and I export the content say to a json file or plugin package, I would like to reset the change count because this indicates the tiddlers no longer need saving because they have being saved via an export. 

The changecount element is essential for the TW saver and UI update handling. ... IMO you want to misuse this element. Exporting 2 out of 3 tiddlers would mean you loose 1 or all 3 tiddlers.

Eg: I open a TW. ... I create 3 tiddlers ... I do export 2 of them. ... Export clears changecount (and dirty-flag) ... I do a page reload. ... I physically lost 1 tiddler. ...

What if creating this tiddler took me 3 hours? ... I would be really disappointed.

 
One strong use case it if a user is on a readonly wiki, such as where they do not have a suitable saver or access to save, eg github hosted/php hosted etc.. then they could fill out a survey. Once they export their survey answers, the they are not longer "unsaved" changes, I can reset the dirty indicator and they can leave the site without a warning, until then the dirty indicator will protect them from leaving the site before their changes are saved/exported.

Creating a wiki, that will never set the dirty-flag is simple.

Edit the https://tiddlywiki.com/#%24%3A%2Fconfig%2FSaverFilter tiddler and make the text field empty. Manually save the wiki and you are done.
 
A similar method may be used if the package of tiddlers are sent as an attachment by email (which I am yet to build)

Possible issue
  • I am not sure if the local storage plugin relies on this same mechanism? However this could be a way to clear the dirty indicator for items saved in local storage. 
It's a saving mechanism. If you say it shouldn't save, it doesn't.
  • Will this disrupt the save mechanisms?
Yes.

Internally there is a function that is called: .wiki.getChangeCount(title), which is used in 12 different core modules. They are all saver and syncer related. ... So changing it "hard core" will deffinitely have unknown side effects. ... Especially since the status is "synced" between 2 different tiddler memory "stores".

As I wrote, it will take much more time to see the side effects. ...

I think you'll need something extremely application specific, which can best be accomplished with a plugin to start off.

-mario
Reply all
Reply to author
Forward
0 new messages