sverweij / mscgen_js

text => sequence charts
https://mscgen.js.org
GNU General Public License v3.0
206 stars 25 forks source link

Make the charts persistent through location hash or history API #142

Closed fflorent closed 9 years ago

fflorent commented 9 years ago

When entering some texts, you could make the changes persistent, using the location hash or the history API (history.push, ...).

For example, here is how the sweetjs editor stores the text in the URL: [click here](http://sweetjs.org/browser/editor.html#/*%0AWelcome to sweet.js!%0A%0AYou can play around with macro writing here on the left side and%0Ayour code will automatically be compiled on the right. This page%0Awill also save your code to localStorage on every successful%0Acompile so feel free to close the page and come back later!%0A*/%0A%0A// Here is a really simple identity macro to get started.%0A%0A// The macro keyword is used to create and name new macros.%0Amacro id {%0A rule {%0A // after the macro name, match:%0A // %281%29 a open paren%0A // %282%29 a single token and bind it to $x%0A // %283%29 a close paren%0A %28$x%29%0A } => {%0A // just return the token we bound to $x%0A $x%0A }%0A}%0Aid %28 42 %29;%0A%0A// Note that a single token to sweet.js includes matched%0A// delimiters not just numbers and identifiers. For example,%0A// an array with all of its elements counts as one token:%0Aid %28[1,2,3]%29%0A%0A// One of the really important things sweet.js does is protect%0A// macros from unintentionally binding or capturing variables they%0A// weren't supposed to. This is called hygiene and to enforce hygiene%0A// sweet.js must carefully rename all variable names.%0A%0Avar x; // note the different name on the right --->%0A%0A// For example, let's look at the swap macro that uses a temporary%0A// variable to swap the contents of two other vars:%0Amacro swap {%0A rule {%0A %28$x, $y%29%0A } => {%0A var tmp = $y;%0A $y = $x;%0A $x = tmp;%0A }%0A}%0A%0Avar foo = 100;%0Avar bar = 200;%0Avar tmp = 'my other temporary variable';%0A%0Aswap %28foo, bar%29%0A%0A// Notice that even though the tmp variable we made outside of%0A// the macro had the same name as the tmp variable inside the%0A// macro, sweet.js kept them distinct.%0A)

Florent

sverweij commented 9 years ago

Thanks for this suggestion ..

I've actually been been toying with persistency:

HOWTO

fflorent commented 9 years ago

Looks nice. And yeah, if you could update the current URL as we type text, that would be neater :).

Florent

sverweij commented 9 years ago

Implemented, tested (as you can see in #145) & deployed.

Try it e.g. with this url :-)

fflorent commented 9 years ago

Ahah, mais oui, c'est vraiment superbe ! :)

Florent

sverweij commented 9 years ago

I'll close the issue then. Thanks for your suggestion!

fflorent commented 9 years ago

My pleasure, thank you for having implemented it :).

Florent