*Examples here are simplified.*
It will get techy, but I tried to "go slow" ;)
On Monday, September 17, 2018 at 1:12:01 PM UTC+2, Mat wrote:
...
> Is that a limitation caused by TW or is it something more fundamental e.g
> to json?
>
JSON means JavaScript Object Notation. .. In js an *object *is a *memory*-
*container*. .. The sign for an object is *{}*
eg: creating a tiddler object looks like this:
var tiddler = {}; // will create an empty object.
To add different elements we can use the "variable dot-notation"
tiddler.title = "New Tiddler"
tiddler.created = ...
tiddler.modified =
tiddler. ...
As you can see, it's not possible to use the same name for 2 different
memory elements.
eg:
tiddler.title = "test";
tiddler.title = "New Tiddler";
The last one executed would win. That's why object elements need to have
unique names!
Since objects are "omnipresent" in JS the browser access routines are
highly optimized and accessing an existing element by name should be by far
the fastest possible way to access memory.
That's why TW uses this mechanism to manage the internal tiddler store [1],
which is named wiki: wiki = {}
The JSON representation looks something like this
"wiki" : {
"New Tiddler": {
"fields": {
"title": "New Tiddler",
"created": DATE object
"modified": DATE object
"tags": [] // array
// and so on
}
},
"test": {
"fields": {
"title": "test",
"created": DATE object
"modified": DATE object
"tags": [] // array
// and so on
}
},
}
So if I would want to access the content of the "test" tiddler, I would
write it like this:
var testTiddler = wiki.test;
// Since spaces are not allowed in JS variable names "New Tiddler" can be
accessed like this:
var newTiddler = wiki["New Tiddler"]
// Accessing variables like this is considered performant.
Performance is the main reason, why tiddler titles have to be unique. They
are "container-names".
That fields.title is the same as the container name is a coincidence (It
makes it easier for human programmers :). This is an implementation detail.
It can _not_ be exploited! Software that "mis-uses" implementation details
will fail, since the implementation can and will change over time!
I must assume the former so/but in TWX anything is possible ;-)
>
The JS object mechanism is probably here to stay :)
have fun!
-mario
[1] You can see the TW store
- if you open tiddlywiki.com,
- open the dev-console: F12,
- select the "console" tab and insert:
$tw.wiki.getTiddler("HelloThere");
[ENTER] // Will open the HelloThere object
$tw.wiki.getTiddlers(); // Will show them all.
If you click the output, it can be expanded ...
--
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/7285b845-571d-4c9a-a07d-5ada49a0f2d2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.