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

Add options objects so we can have namespace/bundle support #2

Merged
merged 1 commit into from
Apr 23, 2019

Conversation

tedkulp
Copy link
Contributor

@tedkulp tedkulp commented Mar 10, 2019

First pass at this. It compiles correctly, but I want to make sure that it looks like the kind of API you want before I do any documentation fixes. If it looks good, then I can do that.

I also wasn't totally sure how to get it to do a full build like in the downloaded version from npm, so I couldn't just drop it into my nodecg bundle to know if it works exactly as the old one did.

Fixes #1

Copy link
Member

@Hoishin Hoishin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR! Sorry for late reviews.

*/
export const useReplicant = <T>(
repName: string,
initialValue: T,
options?: UseReplicantOptions,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd become simpler with initialValue combined with options.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some way to do runtime checking of a type? Or do I basically have to check if options has any of the options arguments (bundle, namespace, etc) and if not, then treat it like an initial value? Like:

if (object && object.namespace)
  // I'm an options
else 
  // I'm an initialivalue

?

Copy link
Contributor

@CarlosFdez CarlosFdez Apr 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately given how flexible Replicants are, I don't think merging them will work. The only real choice I can think of here is to remove initialValue and use options instead. Options provides a defaultValue parameter as a substitute.

It'd be a breaking change but pre-release that's not too big a deal. You could also handle it by making a separate function and making the existing one proxy to that one.

const replicant = nodecg.Replicant(repName, {
defaultValue: initialValue,
});
let replicant: any;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember correctly, the function nodecg.Replicant() returns a value with type Replicant (confusing but that's what happens...). It may be possible to avoid any here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I'll check that out. I wasn't aware of any of the nodecg types.

@CarlosFdez
Copy link
Contributor

CarlosFdez commented Apr 20, 2019

I'm tempted on completing this PR if you think its a good state to start from. Otherwise I could start from scratch. Personally I want access to the persistant flag from the client side (using it to store client side state between runs).

However it'd depend on what you want to do with the useReplicant function. Its either make a breaking change and pass the same object that the regular function takes, or make a separate function to handle it I think.

@tedkulp
Copy link
Contributor Author

tedkulp commented Apr 20, 2019

@CarlosFdez I'd be interested to see what you had in mind. I'm still just using my fork for now, but personally breaking changes don't matter that much. I'm not sure what Hoishin thinks, though.

@Hoishin
Copy link
Member

Hoishin commented Apr 21, 2019

I'm sorry for leaving this PR for long time.

As I mentioned here, we should probably make different change to the API so that it accepts replicant instances instead of name of replicants.
#3 (comment)

What do you think?

@Hoishin
Copy link
Member

Hoishin commented Apr 23, 2019

I'll merge this for now. Any improvements regarding to what I commented is welcome, and I'll try to do that as well.

@Hoishin Hoishin merged commit 80805fb into nodecg:master Apr 23, 2019
Hoishin pushed a commit that referenced this pull request Apr 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

useReplicant doesn't support namespaces
3 participants