On Monday, July 13, 2015 at 6:51:49 AM UTC-7, PMario wrote:
>
> I think using cookies is a bad thing. we used cookies in TWClassik and 
> they just caused problems. imo you could add a new field eg: publish and 
> sort your own recent list. so if you think your changes are worh a new 
> read, just change this field. if not, just don't update the field. 


Cookies are a bad thing when they are being misused, but they still have 
their place...

In general, TW5 stores everything in tiddler fields, so that all 
stateful-ness can be saved with the document.  This provides much greater 
consistency and reliability of handling as compared to cookies.  However, 
in order for changed values to persist, it requires the ability to save the 
document, which most *visitors* to the published document won't have.

In addition, tiddler-based storage is not useful for tracking 
visitor-specific information, such as "when did this visitor last view this 
document" or "what was the last tiddler viewed by this visitor", etc.  This 
kind of information is different for each person who visits the page, and 
should *not* be saved with the document. Similarly, various option settings 
(e.g., story view (classic, zoomin, etc.), show/hide Sidebar) should be 
saved separately for each visitor, so that their desired display 
preferences could be automatically re-applied each time they visit the 
document.

To address this need for visitor-specific persistent information , I've 
implemented a "cookie binding" widget:
   http://tiddlytools.github.io/InsideTW/#TWBook%2FCookies%2Fcookie.js

The widget syntax is:
   <$cookie name="..." tiddler="..." field="..." index="..."/>
where:
   name = the name of the cookie to store
   tiddler = the title of the tiddler containing the field/index value to 
track
   field = a fieldname within the tiddler
     or
   index = an attribute name within a DataTiddler

To create a cookie binding, add the <$cookie> widget to a tiddler tagged 
with $:/tags/PageTemplate.  When first rendered, the <$cookie> widgets will 
retrieve the saved cookie values (if any) and apply them to the 
corresponding tiddler fields/attributes.  From then on, any changes to the 
tiddler fields/attributes during the session are automatically pushed back 
to the cookie values, so they stay in sync with the current tiddler values. 
 When the document is closed *without saving*, the changed tiddler values 
are discarded, but the cookie values remain, so that they can be re-applied 
the next time the document is loaded.

To see this in action, just click on the "gear" icon in the upper right of 
the InsideTiddlyWiki document, and change some display settings (e.g., pick 
a different page background).  Then, reload the page, and see that your 
choices are automatically re-applied.  You can also use your browser's 
cookie management functions to directly view/edit/delete the cookies that 
were saved, and if you delete those cookies, and re-load the page you will 
see that the display settings revert back to the defaults that are saved in 
the document.

Note: there are also a few other widgets and macros for cookie handling:

* TWBook/Cookies/action-setcookie.js
   <$action-setcookie name="..." value="..."/>
   used with <$button> to explicitly set/clear a cookie value
   note: a blank value (i.e., value="") removes the cookie

TWBook/Cookies/getcookie.js
   <<getCookie name:"cookiename">>
   returns the value of the specified cookie
   use for direct display, or in filters, or in <$set>

TWBook/Cookies/cookienames.js
   <<cookienames>>
   primarily used with filters, returns the list of all cookie names for 
the current document

TWBook/Cookies/CookieJar
   declares <$cookie> bindings for settings ("OPT_*"), favorites ("FAV_*"), 
and Table of Contents "toggles" ("TOC_")
   note: this tiddler is tagged "$:/tags/PageTemplate so that the cookie 
widgets can use the TW core refresh cycle to continously "listen" for 
tiddler changes

enjoy,
-e
Eric Shulman
ELS Design Studios
TiddlyTools - "Small Tools for Big Ideas!"
InsideTiddlyWiki: The Missing Manuals

YOUR DONATIONS ARE VERY IMPORTANT!
HELP ME TO HELP YOU - MAKE A CONTRIBUTION TO MY "TIP JAR"...
   http://TiddlyTools.github.com/fundraising.html#MakeADonation

Professional TiddlyWiki Consulting Services...
Analysis, Design, and Custom Solutions:
   http://www.TiddlyTools.com/#Contact

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to tiddlywiki+unsubscr...@googlegroups.com.
To post to this group, send email to tiddlywiki@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/07e8eae5-eab3-4ed6-addc-4d15fa1d62ba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to