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

Possible to use this outside of the ember framework? #24

Open
speigg opened this issue Apr 3, 2020 · 7 comments
Open

Possible to use this outside of the ember framework? #24

speigg opened this issue Apr 3, 2020 · 7 comments
Labels
enhancement New feature or request

Comments

@speigg
Copy link
Contributor

speigg commented Apr 3, 2020

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.

@pzuraq
Copy link
Collaborator

pzuraq commented Apr 3, 2020

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).

@speigg
Copy link
Contributor Author

speigg commented Apr 3, 2020

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.

@speigg
Copy link
Contributor Author

speigg commented Apr 3, 2020

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

@pzuraq
Copy link
Collaborator

pzuraq commented Apr 3, 2020

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!

@speigg
Copy link
Contributor Author

speigg commented Apr 3, 2020

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

@speigg
Copy link
Contributor Author

speigg commented Apr 3, 2020

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

@chriskrycho chriskrycho added the enhancement New feature or request label Apr 22, 2021
@NullVoxPopuli
Copy link
Collaborator

NullVoxPopuli commented Jun 23, 2023

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)

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

4 participants