userback / widget-js

MIT License
4 stars 3 forks source link

Make `token` optional, allow delay of `init()` #21

Open Shard opened 2 years ago

Shard commented 2 years ago

Allow Userback to just "load" when no token is provided and not call init().

This will allow developers to delay the full initialization of a Userback widget until they know which token they want to use.

ekwoka commented 1 year ago

This is something I'd really appreciate as well!

Looks like a simple PR

Shard commented 1 year ago

Thanks for the PR @ekwoka, I have cut a v0.3.0 release which contains your PR.

I believe to fully complete this Issue there still needs to be a change to handle passing undefined explicitly to @userback/widget/init(). The issue is window.Userback.init() does not support this usage currently!

The only thing that would happen when @userback/widget/init(undefined) is called, is it would not error but load the widget bundle and be ready to accept a follow up init() call that actually includes the token and runs the UserbackWidgetLoader.onLoad() code to properly initialize.

We might look at tweaking the upstream window.Userback.init() in some upcoming work which could make this easier but just incase we don't or if anyone would like to see this earlier and create a PR I will leave the ticket open to note this.

Otherwise thanks again for the improvements made in your PR @ekwoka as it should make implementing this much easier.