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

Computed properties #237

Closed
danielo515 opened this issue Aug 18, 2018 · 4 comments
Closed

Computed properties #237

danielo515 opened this issue Aug 18, 2018 · 4 comments

Comments

@danielo515
Copy link

danielo515 commented Aug 18, 2018

Hello.

I'm trying to make computed properties work, but it is being an imposible task. Every time I try to access a computed property I get a different error. If I try to iterate a computed properties I get an error related to length of undefined, if I just try to sow the property I get an weird error about an unexpected token ):

const commandComponent = command => Moon ({
    root: '#cmd'
    , view: readFileSync (__dirname + '/todo.html', 'utf8')
    , name: ''
    , data: { command }
    , computed: {
        keys: {
            get: function ()
            {
                return ['a','b']
            }
        }
    }
});


export { commandComponent };
<div>
    <div class="form-group form-inline">
        <label>Name this command: </label>
        <input class="form-control form-control-sm" type="text" @bind={name}></input>
        <button id="cmd-execute" class="btn btn-primary btn-sm">Execute</button>
    </div>
    {{keys}}
</div>
@kbrsh
Copy link
Owner

kbrsh commented Aug 19, 2018

There are a couple of issues with your example.

  1. Components are made with Moon.extend, not Moon.
  2. Computed properties exist, but aren't documented yet and use a different way without the tedious computed object.
  3. In your template, you use {{keys}} but the current syntax uses single curly braces.

I'd recommend reading through the documentation or refactoring further, but I'll keep this open until I fix and document computed properties.

@kbrsh
Copy link
Owner

kbrsh commented Aug 19, 2018

With the last few commits, I refactored how data is created in components. Computed properties now work like this:

Moon({
  first: "John",
  last: "Doe",

  get full() {
    return this.first + this.last;
  }
});

It should be releasing soon with Moon v1 beta 3.

@danielo515
Copy link
Author

Hello @kbrsh
I read the documentation extensively and I didn't found any reference to computed properties. If you can point me to the correct section I'll be grateful.
I also researched old issues and code examples on the test folder and I tried all that I found there without luck. I didn't open the issue at first sight, I promise.

The new syntax seems nice, looking forward for it

Regards

@kbrsh
Copy link
Owner

kbrsh commented Aug 9, 2019

@kbrsh kbrsh closed this as completed Aug 9, 2019
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