GithubHelp home page GithubHelp logo

Comments (9)

 avatar commented on May 18, 2024 1

So the function itself would do the class recognition? Ok

from keyv.

wookieb avatar wookieb commented on May 18, 2024 1

@lukechilds No I'm not. That introduces typical data synchronization problem where you need to remember to change other file while changing the other. There is no reasonable way to handle that. I understand your decision and I accept it but I'm not going to participate.

from keyv.

lukechilds avatar lukechilds commented on May 18, 2024

Thanks for the offer of help with TypeScript, but it's just not something I'm interested in supporting. I don't think it would be that beneficial to a project of this size and I'm really trying to focus on simplicity.

Custom serializers are an interesting idea, although I'm not sure that that's something that belongs in Keyv. I'm already handling all of the standard JSON types (+ Buffers).

It seems like if you wanted to serialise a custom class it would make more sense to implement that in your class rather than create a custom serializer that would only work with Keyv.

e.g:

const foo = new Foo();
const fooObj = foo.toObject();
await keyv.set('foo', fooObj);

// Then in the future
const fooObj = await keyv.get('foo');
const foo = Foo.fromObject(fooObj);

from keyv.

wookieb avatar wookieb commented on May 18, 2024

It seems like if you wanted to serialize a custom class it would make more sense to implement that in your class rather than create a custom serializer that would only work with Keyv.

Just having ability to set a function for serialization/deserialization is enough

new Keyv('...', {serializer: myCustomSerializerFunction, deserializer, myCustomerDeserializerFunction});

Now I can fully control how data will be serialized/deserialized.

I don't think it would be that beneficial to a project of this size and I'm really trying to focus on simplicity.

Using typescript for even small libraries have a lot of benefits:

  • best autocompletion ever (right now, IDE is not even able to guess parameters used in constructor for KEYV) which also makes possible to read the docs directly in IDE without looking for README of the project.
  • cleaner and better code with async/await http://wookieb.pl/7-reasons-why-you-should-use-async-await-today/
  • no downsides for Javascript users - huge benefit for Typescript users

from keyv.

lukechilds avatar lukechilds commented on May 18, 2024

Just having ability to set a function for serialization/deserialization is enough

I suppose it would be a pretty minimal change. Ok, I'm not totally against this. Still not really convinced it belongs inside Keyv though. Is there a specific use case you have in mind for this?

Using typescript for even small libraries have a lot of benefits

Auto complete is a good point, however I disagree with your other points. Async/await is not a good reason to use TS, it could be achieved with Babel too or Vanilla JS if I dropped support for older Node.js versions.

And I think TS alienates some JS developers from getting involved. It's not a standard. I also really hate the idea of adding a build step. Vanilla JS is better IMO if you have reasonably modern targets.

Could we get the best of both worlds keeping the project vanilla JS but adding TypeScript definitions?

from keyv.

 avatar commented on May 18, 2024
new Keyv('...', {serializer: myCustomSerializerFunction, deserializer, myCustomerDeserializerFunction});

And when would Key use those two functions? Does it need to recognize when an object is an instance of a certain class and when it isn't?

from keyv.

lukechilds avatar lukechilds commented on May 18, 2024

@MySidesTheyAreGone serialize/deserialize would be set to JSONB.stringify/JSONB.parse by default but could be overridden by the user.

from keyv.

lukechilds avatar lukechilds commented on May 18, 2024

@wookieb Any interest in contributing TypeScript type definitions?

from keyv.

lukechilds avatar lukechilds commented on May 18, 2024

@wookieb I'm gonna close this issue in favour of two new separate issues to make this easier to track.

Thanks for your input!

from keyv.

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.