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

Using the Flow with stamps #25

Open
danielkcz opened this issue Apr 28, 2017 · 7 comments
Open

Using the Flow with stamps #25

danielkcz opened this issue Apr 28, 2017 · 7 comments
Labels

Comments

@danielkcz
Copy link
Collaborator

danielkcz commented Apr 28, 2017

I am really curious what could be done about this to make the whole experience less painful. I am still rather a rookie user of the Flow so it's possible I am just missing some obvious path. Let's consider some very basic stamp like this.

const SomeStamp = stampit.compose({
  methods: {
    usefulMethod(input: string): string {
      return input.toLowercase()
    }
  }
})

It would be really lovely to be able to extract type definition out of this so I can do the following and know that passed object is really an instance of that stamp and I can safely use its method without checking manually.

function(proxy: SomeStamp) {
  proxy.usefulMethod('BOOM')
}

Right now to achieve something like that I have to essentially duplicate all signatures to a separate interface type.

interface SomeStamp {
    usefulMethod(input: string): string
}

However, that's rather tedious and not that useful in the end. I am aware that C++ has header files that are kinda similar, but there is at least a compiler that can scream when something is out of sync.

Any ideas what about can be done about this? I am certain it would bring stamps to another level of existence. It gets even more powerful with composing a multiple number of small stamps together.

@danielkcz
Copy link
Collaborator Author

Hm, no one has an idea how to approach this? Is that perhaps disadvantage of stamps?

@koresar
Copy link
Member

koresar commented May 7, 2017

Flow/TS/else require support from the tooling. By tooling I mean IDEs and/or transpilers.

Just like classes - IDEs know how to highlight and lint classes. But they don't know how to lint stamps. E.g. Atom would require a plugin to highlight syntax and do typeahead.

Flow and TS are not pluginable AFAIK. We can't teach them to type check stamps. (Am I right?)
But eslint is pluignable. Something like eslint-plugin-stamp would do. :)

@danielkcz
Copy link
Collaborator Author

That's interesting. Didn't thought about it this way before. Actually, the flow-runtime seems to be a good candidate for this. There is a babel-plugin-flow-runtime which can transform Flow annotations to a runtime code. Same thing could be theoretically done for stamps.

Sadly this would require someone more familiar with AST and stuff. I still haven't been able to wrap my head around it. Everything I've seen looks too messy for my taste.

@koresar
Copy link
Member

koresar commented May 7, 2017 via email

@danielkcz
Copy link
Collaborator Author

Uhh, what? :) Stamps don't work with instanceOf or do they now? I am not even sure what that would solve. The plugin would need to essentially add dynamic annotations based on the descriptor before it spits out to babel plugin to do a transformation.

@koresar
Copy link
Member

koresar commented May 7, 2017 via email

@koresar koresar closed this as completed Apr 12, 2018
@koresar koresar reopened this Apr 12, 2018
@koresar
Copy link
Member

koresar commented Apr 12, 2018

@FredyC JFYI instanceof can be implemented as a utility stamp. Here, I wrote one:
https://www.npmjs.com/package/@stamp/instanceof

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants