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

automatically create object structure #129

Closed
devmondo opened this issue Jul 7, 2015 · 11 comments
Closed

automatically create object structure #129

devmondo opened this issue Jul 7, 2015 · 11 comments
Labels

Comments

@devmondo
Copy link

devmondo commented Jul 7, 2015

hi, i have the following scenario where i have user object

let user ={}

when i bind in html like this

<input value.bind="user.personal.name">

i get undefined in the textbox, but if i make user like this let user={personal:{}}
undefined in textbox goes away, i can understand this behavior if we are using something like c# because it is a statically typed languge but javascript is dynamic and left this constrain from us.

please consider this, thanks in advanced.

@jdanyow
Copy link
Contributor

jdanyow commented Jul 7, 2015

gitter discussion: ☝️ July 7, 2015 4:46 PM

The request is to make the binding system automatically "define" undefined path expressions.

Binding behavior maybe?

@EisenbergEffect
Copy link
Contributor

@devmondo Do you mean that you get the word "undefined" appearing in the text box? If so, I think we should look into fixing that in the core.

@devmondo
Copy link
Author

@EisenbergEffect yeah exactly, it is really troublesome with huge object structure, thanks :)

@jdanyow
Copy link
Contributor

jdanyow commented Jul 23, 2015

@devmondo are you still able to reproduce this? This example works for me using the current bits:

export class App {
  user = {};

  constructor() {
    setInterval(() => this.debug = JSON.stringify(this.user), 500);
  }
}
<template>
  <p>user = ${debug}</p>

  <input type="text" value.bind="user.personal.name">
</template>

@devmondo
Copy link
Author

@jdanyow it is working :) so you guys worked on it to make sure it is not false alarm?

@jdanyow
Copy link
Contributor

jdanyow commented Jul 23, 2015

Nice- yeah I was just going through the binding repo issues to see what was outstanding.

@jdanyow jdanyow closed this as completed Jul 23, 2015
@devmondo
Copy link
Author

i dont know if it is me or not, but if i do this

 this.user.personal.numbers=[1,2,3];

i get inner error: TypeError: Cannot set property 'cool' of undefined
unless i do this

 this.user.personal={};

@EisenbergEffect
Copy link
Contributor

My guess is that your "personal" reference is undefined. We don't actually change your objects (I don't think), but the binding system can safely evaluate undefined paths. For your own code in JS, you will need to handle setting up all the references.

@jdanyow
Copy link
Contributor

jdanyow commented Jul 23, 2015

@EisenbergEffect / @devmondo here's a plunkr that shows what happens:

http://plnkr.co/edit/HnNmfzVqnQhsOkQCWpXn?p=preview

once you type in the textbox you'll see the feature that @devmondo was asking for (magic creation of object structure). Personally I think this is weird and would not expect it to work this way but hey- it works 😉

Here's the code I think is responsible: https://github.com/aurelia/binding/blob/master/src/ast.js#L240-L243

@EisenbergEffect
Copy link
Contributor

Ah yes....it does work. I remember that.

@devmondo
Copy link
Author

@jdanyow @EisenbergEffect i know it is weird, but sometimes it is really needed :) but hey you guys know what can and cant be done

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

No branches or pull requests

3 participants