tracked-tools/tracked-built-ins

Possible to use this outside of the ember framework?

speigg opened this issue · 7 comments

From what I can tell, it doesn't appear that I can simply npm install this package and use it in a non-ember project like a typical npm package. Autotracking is exactly what I need for my project, but if my assumption is correct that I can't use this (as-is) outside of ember, it looks like I may have to just grab the relevant bits (including @glimmer/tracking) and maintain a similar functionality myself.

Currently it isn't setup that way, but this is a goal I have! The main thing we need to do is solidify the low-level APIs we want to expose from @glimmer/tracking in Ember first, then I think the path to releasing this in a stand-alone form would be pretty doable (mainly, just set it up to be consumable via standard webpack bundler).

Hmm, actually after taking a closer look it seems like @glimmer/tracking and @glimmer/validator can be consumed as normal npm dependencies... I think only tracked-built-ins and tracked-sets-and-maps are Ember addons? I can probably just stick with the core autotracking libraries for now, and hack together a simplified version of TrackedArray.

But yes, tracked-built-ins would be a great stand-alone package!

Yes, the other two could be used independently. The concern I would have is that we plan on updating the APIs they expose, since they aren't public yet. @glimmer/tracking is pretty stable, but @glimmer/validator is not quite yet.

We do follow SemVer for those packages, so it would be a proper version bump if we made breaking changes. I expect in the near future we will finalize a design for a final public API that will be made available from @glimmer/tracking, and that will be very stable.

If you want to avoid churn as much as possible, I would use only the two following imports:

import { tracked } from '@glimmer/tracking';
import { memoizeTracked } from '@glimmer/validator';

You can use tricks like I have in this repo with @tracked to get all the autotracking/consumable state you need.

Also! If you do go down that route, and want to make a PR to make this addon consumable as a normal NPM package, would be happy to merge 😄 Main thing you need to do is customize the ember-addon main file, so that it points to something other than the package's main file: https://github.com/glimmerjs/glimmer.js/blob/master/packages/%40glimmer/component/package.json#L92

And then point the package's main at the correct index. We could do the same for tracked-maps-and-sets. May take a bit of finagling, but definitely something I want to do eventually!

I'm not familiar (at all) with the ember ecosystem, so I'm not confident with making and testing such a change.

Thanks for the tips, looks like memoizeTracked was recently added (I was looking for something like that a few days ago!).

following up -- medium term, It's looking like Starbeam will be the reactivity library extracted from glimmer/ember: https://www.starbeamjs.com/

Here are the docs / intro to "reactive collections": https://www.starbeamjs.com/guides/collections.html
the implementations are basically copied from tracked-built-ins.

(however, there isn't an easy way to use Starbeam with ember/glimmer yet)