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 define write handler behavior on the prototype #27

Closed
tgriesser opened this issue Mar 12, 2015 · 4 comments
Closed

Ability to define write handler behavior on the prototype #27

tgriesser opened this issue Mar 12, 2015 · 4 comments

Comments

@tgriesser
Copy link

As I was writing out the issue for defining a transformer protocol over on transducers-js, it occurred to me that it would be super handy if there were a similar convention for defining a write handlers in transit.

This would be great for wanting to bake in support for transit serialization without needing to require the library (since that's something you really only want to pull at the application layer).

function PointHandler(x, y) {
  this.x = x
  this.y = y
}
PointHandler.prototype['@@transitWriter'] = function() {
  return {
    tag: 'point',
    rep: [this.x, this.y],
    stringRep: null
  }
}

Perhaps this could be the final check if a write handler is not otherwise defined for the object's constructor so folks aren't restricted to a pre-defined handler - registering an object through the traditional means would take precedence.

@swannodette
Copy link
Contributor

@tgriesser thanks for bringing this up, will think about it.

@tgriesser
Copy link
Author

What I'm actually after here can actually be implemented with transitTag 5bea1bb.

I didn't see this behavior documented anywhere, is it something can be relied on?

@swannodette
Copy link
Contributor

@tgriesser yep, it can be relied on! Feel free to document on the wiki. Thanks :)

@tgriesser
Copy link
Author

Well would you look at that... it's already there :)

https://github.com/cognitect/transit-js/wiki/Getting-Started#avoiding-duplication

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