abelljs/abell

[IDEA, POLL] Importing variables rather than having it available by default.

Closed this issue · 7 comments

Option 1

index.abell

{{
  const { globalMeta } = require('abell');
}}

<html>
<body>
  {{ globalMeta.siteName }}
</body>
</html>

[$path]/index.abell

{{
  const { $contentObj, $path } = require('abell');
  const meta = $contentObj[$path];
}}

<html>
<body>
  {{ meta.title }}
</body>
</html>

vs

Option 2 (The current way)

index.abell

<html>
<body>
  {{ globalMeta.siteName }}
</body>
</html>

[$path]/index.abell

<html>
<body>
  {{ meta.title }}
</body>
</html>

EDIT:

Option 3

index.abell

{{
  const { globalMeta } = variables;
}}

<html>
<body>
  {{ globalMeta.siteName }}
</body>
</html>

[$path]/index.abell

{{
  const { meta } = variables;
}}

<html>
<body>
  {{ meta.title }}
</body>
</html>

We can change name of variables in option 3 to self, globalVariables, abellVariables, or abell

I kinda like,

const { globalMeta } = abell;

Can you all drop 1, 2 or 3 in the comments and tell which one you prefer, and why?

Definitely 1.

2 looks like magical imports so definitely not that.

1 does look a little ugly and 2 looks very easy to use. But although 1 looks ugly, it is more robust and gives the exact view on what's happening. So I vote for 1. Quality wins.

Thank you @akash-joshi and @Krishnamoorthy12, Would you mind checking the message again? I've added an option 3 in it

Again, 3 looks clean. But I'd stick with 1. Omitting details might make users wonder how things work. It'd be nice if 1 could be a little bit cleaner.. without hiding important information.

Makes sense! But in option 1 when we do

const { $path } = require('abell');

It actually reads dynamic variable and not the static (value of $path will defer depending on the file it is being called from).

Usually, when we require/import something, we expect a static variable and if someone tries to follow the import and see the export inside abell, he won't be able to see that variable. So I am in doubt about the implementation of 1

Makes sense! But in option 1 when we do

const { $path } = require('abell');

It actually reads dynamic variable and not the static (value of $path will defer depending on the file it is being called from).

Usually, when we require/import something, we expect a static variable and if someone tries to follow the import and see the export inside abell, he won't be able to see that variable. So I am in doubt about the implementation of 1

You have a point. This makes sense. Go with 3 then, but definitely not 2.

const { globalMeta } = Abell;

is the way we go! Thank you for your views on this everyone 🎉