Skip to content
This repository has been archived by the owner on Feb 19, 2022. It is now read-only.

Possibility to return undefined from template expression #80

Open
ismay opened this issue May 7, 2017 · 2 comments
Open

Possibility to return undefined from template expression #80

ismay opened this issue May 7, 2017 · 2 comments

Comments

@ismay
Copy link

ismay commented May 7, 2017

I'm using rapscallion and am using helmet to render a title and meta description (see here):

        <div id="app">${appRenderer}</div>
          // ...
          // Set title and meta description
          ${() => {
            helmet = Helmet.renderStatic()
            return ''
          }}
          appendToHead('${() => helmet.title.toString()}')
          appendToHead('${() => helmet.meta.toString()}')

Now helmet needs to be instantiated after rendering the app, but since rapscallion throws an error when returning undefined from an expression* I'm just returning an empty string. This isn't really a big deal and the current solution works fine.

But, I thought it might be nice to allow expressions that evaluate to undefined, which would then just insert nothing. No idea if that's possible or even desirable, but it would allow me to omit the return ''.

*: throw new Error("Unknown value in template of type " + (typeof segment === "undefined" ? "undefined" : _typeof(segment)) + ": " + segment);

@jamesjjk
Copy link

@ismay How did you achieve appendToHead?

@ismay
Copy link
Author

ismay commented Jun 12, 2017

@jamesjjk This is what I used:

<script>
document.head.insertAdjacentHTML('beforeend', '${whateverYouWantToInsertHere}')
</script>

Don't know if it's the best way, but it worked for me.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants