Giter Club home page Giter Club logo

Comments (2)

lxsmnsyc avatar lxsmnsyc commented on July 29, 2024 1

This reminded me of React's Taint API which usually raises an error when an expected (or in your words, marked) value is encountered during serialization. I did consider this before however there were three reasons why I didn't:

  • I didn't like the API. I just don't like marking the value globally.
  • The internal map might be a source of memory leak.
  • Users can just wrap their own values with an unserializable value.

Now in your case it's a bit different since it doesn't exactly raise an error, it just omits the value. Usually my answer here would be to "defer this problem to the user by making the necessary changes manually" however this might be considered and can open as an opportunity. I like the idea of omitting, but I just need to have a decent API for this.

Here's some of my ideas:

  • Introduce a UnserializableReference class which is basically just a class with a value property that holds the value you want to hide from the serializer e.g. new UnserializableReference(value) then you can access value if you want to recover it.
  • Introduce a UnserializableReference abstract class. This is one is just for inheritance check, but not might be ideal. It works, but i'm still 50/50.
  • Instead of a class, we do an object with an specific symbol. Usually I would provide an API for this (createUnserializableReference perhaps)

Now the term unserializable itself might not be a great term, hidden might be good replacement term, there's also opaque, but that's just me. I'd like to discuss the name.

Also, as expected here, if the value is encountered, it's going to be replaced by a new value (by default it would be undefined HOWEVER I'm thinking of allowing this to be configurable through the reference creation e.g. createUnserializableReference(value, replacement)), and once the value is serializable, I would expect the users to expect that deserializing the value will not able to recover whatever that value is.

from seroval.

XiNiHa avatar XiNiHa commented on July 29, 2024

Thanks for looking into the issue! Between the ideas, I like the first and the third one, mostly because the second one requires creating a separate class. For the naming, I also can think of skip, but I'm happy with anything else 😅 I also love the customizable replacement value idea!

from seroval.

Related Issues (18)

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.