GithubHelp home page GithubHelp logo

Comments (14)

brad avatar brad commented on August 18, 2024

@gliechtenstein Maybe this is a silly question, but why can't we make $jason the keyword (instead of $root) and say you are not allowed to use $jason as an object key, as in $jason.posts[1].$jason.username. Is there any reason why one would want to use the name $jason in child like that?

from documentation.

gliechtenstein avatar gliechtenstein commented on August 18, 2024

Hmm, then how would we express the $jason objects that are returned from actions as return values?

For example, when we $render, the template always starts with

{
  "templates": {
    "body": {
      "sections": [{
        "items": {
          "{{#each $jason}}": {
            "type": "label",
            "text": "{{name}}"
          }
        }
      }]
    }
  }
}

from documentation.

brad avatar brad commented on August 18, 2024

@gliechtenstein Ahh, good point. I didn't see the whole picture. I like the idea of introducing $root and I'm personally happy with the name. 👍

from documentation.

sg02 avatar sg02 commented on August 18, 2024

I guess $ stands for a variable, # stands as an evaluation.

And now, '#.variable' might mean a value of a sub variable for any of string or array.

In case hierarchy of variable is needed, it may be expressed by . and - just like in typescript.

from documentation.

sg02 avatar sg02 commented on August 18, 2024

The above proposal is possibly combined with js elements. (without html template {{ }} code)
Perhaps, // is comment in js and might be hidden evaluations.
And its line is started with //# without any spaces for the first time.

Then, the synergy of # and // stand for evaluation and comment like these:

{{ #if }}
==>
//#if

"{{ $jason.username }}"
==>
"#.username"

"{{ #each $json.posts }}" : {
  ...
}
==> 
//#each "$json.posts" : {
  ...
//}

from documentation.

sg02 avatar sg02 commented on August 18, 2024

Without any of even js elements,

#if

"#.username"

"##each $json.posts##"

The sign # for single word, ## for sentences, they themself are just evaluating area.

from documentation.

gliechtenstein avatar gliechtenstein commented on August 18, 2024

@sg02 thanks for sharing the idea!

If I understand correctly, you're suggesting we use # as the delimiter for any template expressions within a string, right?

One thing I realized while investigating different options is these symbols used to declare the range of a template needs to have a direction. For example {{ or <%= marks the beginning and }} or %> marks the end.

If we don't have this type of directionality, there are many edge cases the template engine won't be able to handle easily, for example imagine this case:

$jason = {
  "sound": "ha"
};

And we have a template that looks like this:

{
  "message": "I laugh: {{$jason.sound}},{{$jason.sound}},{{$jason.sound}}"
}

If we convert this into the # syntax,

{
  "message": "I laugh: #$jason.sound#,#$jason.sound#,#$jason.sound#"
}

As you can see, it's not easy to quickly see what's going on here, unless you figure out the entire nested structure of the string you never know whether $jason.sound or , in the #$jason.sound#,# sequence is the template. And it's not just hard for humans, without a clear direction it becomes harder for the engine to parse since it needs to create a nested structure every time the parsing is done, and there's no need to introduce this complexity when you can simply choose another token with directionality. And I think that's why all template engines have a distinct beginning token and an ending token.

Also another factor is that # is a css ID selector. And the template engine sometimes uses jQuery syntax to parse HTML into JSON (See here) and this would be problematic.

Basically it all comes down to:

  1. The token should not conflict with any JS/CSS keywords
  2. Needs to be easy to parse (both for humans and the machines)

p.s.
Plot twist: BTW this thread is not about what you were thinking haha, it's about supporting the $root context. Maybe I should create a separate issue for the "what token to use for declaring templates"

from documentation.

sg02 avatar sg02 commented on August 18, 2024

I recommended these 3 types. (I know it's easy to humans but machines also know its start by '#'.)

1. #reserved_keyword_only

2. #.variable_to_be_a_single_value

3. ##u_may_write_even_ur_long_fuction##

I agree that html template engine has been number 3 type only.

And your example is number 2 type like these:

As-was example:

{
  "message": "I laugh: {{$jason.sound}},{{$jason.sound}},{{$jason.sound}}"
}

To-be example:

{
  "message": "I laugh: #.sound,#.sound,#.sound"
}

Please, notice that a single variable will be just a value with '#.'. And it means that it's like just js closures seemingly.

And css hexadecimal color could not be any of reserved keywords.

P.S.:
As I see, $root would remain in the code but not be used by most users. And it's about template engine. ;)

from documentation.

gliechtenstein avatar gliechtenstein commented on August 18, 2024

How would i do something like this?

{
  "message": "I laugh: ha.ha.ha.he"
}

Maybe like this?

{
  "message": "I laugh: #.sound.#.sound.#.sound.he"
}

What if #.sound actually has an attribute named #? Or if it had an attribute called he? How do we know if the user intended to access those attributes or if they just meant to print "#" ro "he"?

from documentation.

sg02 avatar sg02 commented on August 18, 2024

Well, how about ^# or #^ as an escape character to avoid js conflict?

And it's no problem at all with he, I guess. Because #.single_word is literally a single word.

from documentation.

gliechtenstein avatar gliechtenstein commented on August 18, 2024

Well, how about ^# or #^ as an escape character to avoid js conflict?

Haha yes I've been asking you these questions not because I disagree with you completely but because this was exactly the thought process I went through--I had the same idea (just use a hashtag!) and had tried to make it work--and what started out as a clean solution started looking weird as I tried to support complex situations like these (I actually tried rewriting some markups into this notation #^ ... ^# and it ended up looking horrible compared to the {{ }}, which was the opposite of what was intended).

Because #.single_word is literally a single word.

I'm not sure if I understood correctly but why is it just a single word? it can be an array or an object too. For example:

{
  "items": {{$jason.items}}"
}

can be parsed into something like

{
  "items": ["a", "b", "c"]
}

from documentation.

sg02 avatar sg02 commented on August 18, 2024

About using an escape character for the raw printing mode,
someone meant to print #, it might be written as #^#.
because the escape character is #^.
someone meant to print #, it might be written as ^##.
because the escape character is ^#.

(Easy to find # first and ^ after.)

Your example will be like:

{
  "items": #.items
}

(Btw, it's not about "items": "#.items", without double quotes! -.-;)
and so I will change the definition a bit like:

2. #.single_word_variable_to_be_a_single_line_by_preprocessing

you can notice that #.single_word is still itself and its result could be anything.

In case, to expand single_word to hierachy_word, it may be changed from . to - and would be more complex and postponed to implementing. And I would prefer to use ## something_with_my_complex ##

You want to use number 3 type only, I think that's ok though with not using {{ }}. because multi-protocol, multi-language and multi-platform preprocessing supports are needed as you regard.

The reason I recommend ## and #, it's already used as a SQL preprocessing mapper sign and used as a comment sign mostly by many of shell scripts. and it could be extend with just like #. or something other.

from documentation.

gliechtenstein avatar gliechtenstein commented on August 18, 2024

Thanks for sharing the idea, I'll take it into account.

Actually, reading your comment and thinking about it more gave me some good ideas. Trying it out right now. Thanks!

from documentation.

sg02 avatar sg02 commented on August 18, 2024

In case, # is used as tokens for templates,
I will change it to## as my recommendations like these:

1. ##:reserved_keyword

2. ##.single_variable

3. ###sentence_like_function###

Only # alone is not proper for uri, html id, c language, etc. to support multi protocol and language.

from documentation.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.