Comments (9)
So the function itself would do the class recognition? Ok
from keyv.
@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.
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.
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.
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.
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.
@MySidesTheyAreGone serialize
/deserialize
would be set to JSONB.stringify
/JSONB.parse
by default but could be overridden by the user.
from keyv.
@wookieb Any interest in contributing TypeScript type definitions?
from keyv.
@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)
- sqlite adapter iterator stack overflows HOT 4
- SSL/TLS Support for Redis Connections HOT 2
- Support for later versions of MongoDB Node.js Driver
- Get rid of json-buffer HOT 3
- ⚠️ Critical dependency: the request of a dependency is an expression HOT 1
- Namespace will be missed using KeyvMongo HOT 2
- Support for setting multiples keys
- Keyv v5 - Features and Release Plans 🎉 HOT 16
- Question HOT 4
- Data not being stored using KeyvRedis - Issue With Typescript HOT 3
- Download failed HOT 1
- `@keyv/redis`: `useRedisSets` option does not take effect when providing `ioredis` instance HOT 1
- RedisJSON with Keyv HOT 5
- Use Redis UNLINK instead of Redis DEL HOT 2
- Check the namespace provided to Redis doesn not include ":" HOT 7
- MaxListenersExceededWarning: Possible EventEmitter memory leak detected. HOT 1
- flaky behaviour for the .has method HOT 5
- Strange compile error after upgrading @keyv/redis to 2.8.1 HOT 4
- How does the TTL work? HOT 1
- import or require webpack error. HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from keyv.