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

Figure out how to handle binding between can-components #6

Open
phillipskevin opened this issue Mar 2, 2017 · 0 comments
Open

Figure out how to handle binding between can-components #6

phillipskevin opened this issue Mar 2, 2017 · 0 comments

Comments

@phillipskevin
Copy link
Owner

phillipskevin commented Mar 2, 2017

By default, if you pass the data object to a can-component it will two-way bind the current view and the component:

const appView = data => {
  return h('div', {}, [
    h('h2', {}, [ 'Children' ]),
    h('a-counter', data)
  ]);
};

You can also manually create a child scope to pass to the component in order to get one-way binding:

const appView = data => {
  const ChildScope = DefineMap.extend({
    // one way (to-parent) bind count
    set count(val) {
      data.count = val;
      return val;
    }
  });

  return h('div', {}, [
    h('h2', {}, [ 'Children' ]),
    h('a-counter', new ChildScope())
  ]);
};

This is pretty cumbersome to do whenever you don't want two-way binding, so a better solution is probably out there.

Maybe something like

deriveScope(data, {
  twoWay: [],
  toParent: [ ' count' ],
  toChild: []
};
@phillipskevin phillipskevin changed the title How to handle binding between can-components Figure out how to handle binding between can-components Mar 2, 2017
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

1 participant