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

Ability to specify discriminator name #6

Open
tanfonto opened this issue Sep 19, 2019 · 8 comments
Open

Ability to specify discriminator name #6

tanfonto opened this issue Sep 19, 2019 · 8 comments

Comments

@tanfonto
Copy link

  • I'm submitting a ...
    [ ] bug report
    [ x ] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary
    Something unionize has and can be of use if you need to deal with well established contract like FSA. Currently, I'd need to manually extend the result object influencing performance and - potentially, but hopefully not - breaking some existent behaviours.

@tanfonto
Copy link
Author

Great job otherwise, btw 🙇

@twop
Copy link
Owner

twop commented Sep 21, 2019

Could you provide a little bit more context what you would like to do and why?

One of the explicit decisions I made is to make data structures for values opaque to the user. The reason was to experiment with different representations (and I already changed it twice).

But again, would love to learn more about your usecase

@tanfonto
Copy link
Author

Yeah, sorry for the delay. Put simply, I'd like to be able to tell Union to use field name different than k. Type is something that comes to mind mostly because Redux relies on it. Might be there's something I'm missing, in which case I'm more than open for explanation. Cheers.

@twop
Copy link
Owner

twop commented Sep 24, 2019

No worries!

Got it.

I made a design decision that the shape of the union values is opaque to developer (partially because that how it works in rust/swift etc).

Fun history story:

const U = Union({a: of(null), b: of<string>()})
const val = U.b('aha!');

This union value was originally represented as this:

['b', 'aha!']

then

['b', ['aha!']]

now

// objects are faster because of shape optimizations
{k:'b', p:['aha!']}

And I'm benchmarking

{k:'b', p0:'aha!', p1: undefined, p2: undefined, l:1}

This might be faster because internally I'm using (...args) => {/*...*/} which might stop some optimizations (args shape is not stable, thus hard to jit)

So going back to the issue: I didn't know at the time what would be the fastest internal implementation of the library api. The worst part is that this state is very dynamic and might change at any given moment. So I don't want to expose internal api because it will stop any perf explorations.

Hope that makes sense and answers your question.

@MiracleBlue
Copy link

Sorry for my somewhat off-topic comment @twop but I just had to say that I've been reading your issue replies on this repo and you've given me yet another reason to love the open source community. I'm really looking forward to using this, and seeing if it fits well with what I need, but either way, love your work! I hope you keep doing what you're doing!

@twop
Copy link
Owner

twop commented Dec 24, 2019

@MiracleBlue Thank you so much for such kind words <3
Curious to know more about your use case, please give feedback if you will have time and energy

@MiracleBlue
Copy link

MiracleBlue commented Dec 24, 2019 via email

@twop
Copy link
Owner

twop commented Dec 26, 2019

@MiracleBlue
Nice! I need a good css solution so badly. Offtopic:
Here is what I have in mind:
https://codesandbox.io/s/sketch-of-typed-css-5hlyn (both index.ts and dynStyles.ts)

But for that probably plugin compiler API is a prerequirement:
microsoft/TypeScript#16607 (comment)

Do you have a sketch API? for that?

P.S. probably it makes more sense to move conversation to somewhere else. my twitter handle @twopSK if that is a convenient medium for you.

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

No branches or pull requests

3 participants