On Sun, Feb 17, 2019 at 10:25 AM stefano franchi <[email protected]>
wrote:
[...]

> In particular, there is an issue I have not been able to solve yet, and I
> hope you may help---where do I look to find examples of a callback function
> that would allow the calling code to tell the external library  to save its
> data?
>

This is backwards from the way I've implemented it and seen it implemented
in other widgets. I think the expectation is that the external library
provides a way to register a callback will will be called by the library
every time anything changes. The widget can register a callback in which
the code will ask the library to serialize its data. The resulting data is
saved to some tiddler field in order to persist. In this way, the data is
always in sync with the tiddler field. The widget does not get notified it
is about to be destroyed (that I know of), so having the data always in
sync is required.

I think in a previous exchange you suggested to take a look at the
> Codemirror plugin, but I could not find where the mechanism is implemented.
> I guess it is because I am not really sure what I am looking for.
>


This is the code I had in mind
https://github.com/Jermolene/TiddlyWiki5/blob/master/plugins/tiddlywiki/codemirror/engine.js#L121

// Set up a change event handler
this.cm.on("change",function() {
        self.widget.saveChanges(self.getText());
});

[...]

/*
Get the text of the engine
*/
CodeMirrorEngine.prototype.getText = function() {
return this.cm.getValue();
};


Here's an example I wrote, but it is much more complicated WRT the
persisting of data:
https://github.com/btheado/tweve/blob/master/src/plugins/btheado/tweve/files/eve-widget.js#L61

Here's another one I wrote, but not well commented and probably not a good
example to follow:
https://github.com/btheado/jsoneditor/blob/master/jsoneditor-widget.js#L60



> Your tutorial on the refresh mechanism does a great job of explaining how
> a widget manages to keep itself in sync with the underlying tiddler. It is
> the reverse procedure that is still baffling to me. In particular, is
> complete sync the only option---sending back a call from the widget back to
> the tiddler after every single update? That may not be feasible in case the
> external library works on on  its own internal representation of the
> underlying tiddler data and it may be expensive to convert back and forth
> (as it is in my case). I am thinking a simpler "updateTiddlerOnExit" method
> to call before the widget is destroyed would be more appropriate, but I
> haven't found out how to manage this kind of tiddler-->widget communication.
>

See this related discussion, I don't think TW currently supports what you
are after: https://github.com/Jermolene/TiddlyWiki5/issues/1784

So in your case you are saying the conversion back and forth is too
expensive to always keep in sync? Have you already tried it and found it to
be too slow?

Brian

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/tiddlywikidev.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywikidev/CAO5X8CyZ2%3DnOgYfd-EKxiGUpmUa3LssRj5N%3Dy7r1tnbpTkrkYg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to