Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LambdaContext lookup should return null if no property #44

Open
luaVolk opened this issue May 14, 2019 · 1 comment
Open

LambdaContext lookup should return null if no property #44

luaVolk opened this issue May 14, 2019 · 1 comment

Comments

@luaVolk
Copy link

luaVolk commented May 14, 2019

Let's say i have something like this

{{!index.mustache}}

{{#users}}
...
{{#isBirthday}}
HAPPY BIRTHDAY!!!
{{/isBirthday}}
...
{{/users}}
// app.dart
...

template.render({
  'users': [
    {
      'name': 'guy',
      'age': 18,
      'birthday': {'day': 15, 'month': 5},
    },
    {
      'name': 'gal',
      'age': 22,
    }
  ],
  'isBirthday': (LambdaContext ctx) {
    Map birthday = ctx.lookup('birthday'); // Causes an error because it returns an empty Object on the second person

    if (birthday != null) {
      ...
    }
  }
}, req.response)


...

Wouldn't it make more sense to return null since that's what it actually is?

@xxgreg
Copy link
Owner

xxgreg commented Jun 12, 2019

That makes sense. I guess this is a side effect of strict mode. I guess the workaround in the meantime is to catch the exception rather that using null.

I wonder if a good backwards compatible fix would be to add a 'tryLookup' function which will return null as you require.

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

No branches or pull requests

2 participants