glimmerjs / glimmer-application

[MOVED] This package is now part of the Glimmer.js monorepo
https://github.com/glimmerjs/glimmer.js
30 stars 13 forks source link

Advanced helpers #62

Closed topaxi closed 6 years ago

topaxi commented 7 years ago

I'm not sure if this makes sense in glimmerland, but it would be nice to have a way to have helpers which can update their own values.

Usecases: Timers, Observables, Tasks etc. which emit values asynchronously and need to be destroyed after removal. Manual subscription, timerIds handling can get tedious after a while.

This can obviously be implemented in components, but for attributes/properties this does not seem to be possible.

I'd imagine something like:

export default class SubscribeHelper {
  private sub: Subscription;

  @tracked value: any;

  init(observable: Observable<any>) {
    this.sub = observable.subscribe(v => this.value = v)
  }

  destroy() {
    this.sub.unsubscribe()
  }
}

Usage in template:

<div class={{subscribe currentClass}}>{{subscribe content}}</div>

Inspired by the angular async pipe: https://angular.io/docs/ts/latest/api/common/index/AsyncPipe-pipe.html

locks commented 6 years ago

This repo has been merged with glimmerjs/glimmer.js (into a monorepo setup). I am not sure if this issue is still applicable, but if you could confirm it is still an ongoing concern and open it over there that would be very helpful.

Sorry for the noise, but thank you for your help!