Zhuinden / simple-stack

[ACTIVE] Simple Stack, a backstack library / navigation framework for simpler navigation and state management (for fragments, views, or whatevers).
Apache License 2.0
1.37k stars 74 forks source link

Allow registration of a service while marking it "not to be parcelled" via Bundleable #157

Closed Zhuinden closed 5 years ago

Zhuinden commented 5 years ago

Currently, every added service in every added scope is toBundle()'d by their service tag.

Clearly if a service is registered in multiple scopes with multiple service tags, then saving its state for each scope / service tag is extremely excessive in a world where onSaveInstanceState has a size limit.

Also, fromBundle thankfully now runs only ONCE (before onServiceRegistered), so while it is risky to detect that toBundle() shouldn't be called multiple times, it would definitely make sense for the end user to say "actually this is just the same thing registered by a different name, I don't need state persistence callbacks based on this registration".

Zhuinden commented 5 years ago

Possibly want something like addForLookup/addBundleable.

Of course, the default automatic behavior is super nice, so I definitely wouldn't want to force the user to always add these two things separately.

I wonder how the service lifecycle callbacks would work in this scenario. Should probably still trigger them.

Zhuinden commented 5 years ago

I also like the name rebind, because this generally comes up if you add an object as its own class, but you also bind it as some kind of interface implementation.

It would imply that this service had already been added, so bundleable registration is not needed.

(Should I add any verifications around "rebind should be called for services already added"?)

Zhuinden commented 5 years ago

Eh it should be just be addService(service, false)

Zhuinden commented 5 years ago

That's actually very tacky. I guess I'll just put it off for now...

Zhuinden commented 5 years ago

I like the name bindAlias.

Zhuinden commented 5 years ago

....Ugh, I should not be so trigger happy. 😞

Without serviceBinder.get() returning alias as a service, this feature is actually very problematic!

I need to release 2.0.2 with the fixed semantics.

Zhuinden commented 5 years ago

And then 2.0.3 without the attempt to "make sure the service is registered first, before adding an alias" because I was really screwing it up and I really needed this feature out by now. :thinking:

Zhuinden commented 4 years ago

It was added and it is called serviceBinder.addAlias(), or with the new extensions, serviceBinder.rebind<OtherName>(originalService).