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

Allow scala seq/maps as callback function parameters #5

Closed
ramnivas opened this issue Jun 19, 2015 · 3 comments
Closed

Allow scala seq/maps as callback function parameters #5

ramnivas opened this issue Jun 19, 2015 · 3 comments

Comments

@ramnivas
Copy link
Contributor

Currently, we transform Seq and Map parameters to case classes to js.Array and literal, but still require parameters to callback functions to be of js types (see onChange of TagsInput for example). It will be nice to allow callbacks to specify normal Scala types.

@ramnivas
Copy link
Contributor Author

Here is an outline of how we might do it. Given a component with the following as one of its case class parameter:

onChange: js.UndefOr[Seq[String] => Unit] = js.undefined

The macro will create a js properties to be set for the underlying component:

onChangeJs : js.Array[String] => Unit = arr => {
  onChange(Seq(arr.map(e => elementReader.fromJs(e)): _*)
}

Essentially, we transform the argument with code that is a dual of

js.Array(value.map(e => elementWriter.toJs(e)): _*)
.

@ms-ati
Copy link

ms-ati commented May 18, 2016

Any progress on this?

@ramnivas
Copy link
Contributor Author

Unfortunately, I haven't had a chance to work on this.

nafg added a commit to nafg/scalajs-react-bridge that referenced this issue Nov 22, 2017
Fixes payalabs#5

- Code-generated function instances use an instance to convert their
   return value
- That obviates codegen for Callback-returning functions
- Richer set of JsWriter instances
- No "fallback" JsWriter for any type
- JsWriter convenience factory simplifies defining instances
- Don't handle Option parameters specially in the macro; let
   the typeclasses do the work
- Simplify propsToDynamic
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

2 participants