Giter VIP home page Giter VIP logo

Comments (7)

kateinoigakukun avatar kateinoigakukun commented on July 30, 2024 3

I discussed this topic in the Japanese Swift community and I think ConstructibleFromJSValue and ConvertibleToJSValue are the best pair.

  • JSValueConvertible/JSValueConstructible

This pair is really ambiguous about "input" and "output".

  • JSValueEncodable/JSValueDecodable

It feels like Encode/Decode implies that member methods do some serialization. But our protocol does not serialize but just convert JS/Swift values.

  • JSValueConvertible/ExpressibleByJSValue

From stdlib use cases, ExpressibleBy prefix implies that the protocol is related to literal.

  • JSValueConvertible/ConstructibleFromJSValue

XxxConvertible is used to represent one-way transformation in stdlib, and data info may be lost while transformation.
If the transformation is intended to preserve data info, the protocol has explicit "Lossless" prefix. (e.g. LosslessStringConvertible)

  • ConvertibleToJSValue/ConstructibleFromJSValue

It feels like this pair is the most explicit representation and is precise pair.

from javascriptkit.

j-f1 avatar j-f1 commented on July 30, 2024

The fork I based those implementations off of used JSValueEncodable and JSValueDecodable. I kept the existing names because they match existing type names (like CustomStringConvertible). Maybe JSValueConstructible could be renamed ExpressibleByJSValue to match ExpressibleByStringLiteral?

from javascriptkit.

MaxDesiatov avatar MaxDesiatov commented on July 30, 2024

I like ExpressibleByJSValue 👍

from javascriptkit.

kateinoigakukun avatar kateinoigakukun commented on July 30, 2024

I prefer ConstructibleFromJSValue because ExpressibleByXXX is mainly used for literal expressible types in stdlib.

They are examples of protocol naming uses in stdlib.

  • XXXConvertible: Self -> Target
  • XXXBrigable: Self -> Target & Target -> Self
  • ExpressibleByXXX: Literal -> Self

from javascriptkit.

MaxDesiatov avatar MaxDesiatov commented on July 30, 2024

I also wanted to mention that Expressible is used mainly for literals. But then I recalled that Swift Argument Parser library from Apple folks has ExpressibleByArgument protocol, which is not strictly about literals. Either way, I don't have a strong opinion here about alternatives, I just find the status quo a bit confusing 😅

from javascriptkit.

j-f1 avatar j-f1 commented on July 30, 2024

Created #88. One last thing to consider: is JSValueCodable a good name? Should we rename it or maybe even delete it?

public typealias JSValueCodable = ConvertibleToJSValue & ConstructibleFromJSValue

from javascriptkit.

MaxDesiatov avatar MaxDesiatov commented on July 30, 2024

I just started preparing a PR like that myself, but you were first 😄

I'd suggest JSValueCompatible as a replacement for JSValueCodable.

from javascriptkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.