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

feat: add fromPropertyChange source #1

Closed
2 tasks
alexlafroscia opened this issue Jan 28, 2019 · 1 comment
Closed
2 tasks

feat: add fromPropertyChange source #1

alexlafroscia opened this issue Jan 28, 2019 · 1 comment
Labels
enhancement New feature or request

Comments

@alexlafroscia
Copy link
Owner

alexlafroscia commented Jan 28, 2019

Idea: turn a stream of property changes into an Observable.

import { fromPropertyChange } from 'ember-observable';

export default class Foo extends EmberObject {
  key = value;

  init() {
    super.init(...arguments):

    const observable = fromPropertyChange(this, 'key');
    observable.subscribe(value => {
      console.log(value);
    });
  }
}
  • Automatically unsubscribe once the object is destroyed -- no more need for removeObserver directly
  • Could subscribe use this internally?
@alexlafroscia alexlafroscia added the enhancement New feature or request label Jan 28, 2019
@alexlafroscia
Copy link
Owner Author

Automatically unsubscribe once the object is destroyed -- no more need for removeObserver directly

Probably not necessary, and this would require injecting code into willDestroy -- not great

Could unsubscribe use this internally?

Turns out the safe answer is "no" -- I saw something earlier today saying that an observer should not create a subscription, and refactoring to use fromPropertyChange in the subscribe decorator would require that.

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

No branches or pull requests

1 participant