angular / in-memory-web-api

The code for this project has moved to the angular/angular repo. This repo is now archived.
MIT License
1.18k stars 232 forks source link

feat: added persistence option using indexeddb #166

Closed gionkunz closed 5 years ago

gionkunz commented 6 years ago

This fixes #158 and adds a feature to persist data across multiple browser sessions using IndexedDB to store the in-memory database. Let's discuss the changes and if everything is fine, i'll add more tests and documentation.

gionkunz commented 6 years ago

I've also updated existing code to use RxJS pipe for stream transforming. Hope, that's fine with you.

gionkunz commented 6 years ago

@wardbell, anything missing in that PR which you want me to change?

gionkunz commented 6 years ago

@wardbell bump, I'll annoy you with this PR every other week until you reply :-P

gionkunz commented 6 years ago

@wardbell Any chance you could take a minute to review those changes?

wardbell commented 5 years ago

I'm sorry but I'm not in a position to enhance this library as it belongs to Angular. I can and will fix bugs. But it is difficult to get new features in.

You may want to fork it and take this in your own direction.

FWIW, I've often thought about persisting the data. IndexDB is only one of the ways to do it and I'm not sure I'd want to force it upon someone.

You said it is "optional". Not clear to me at a glance how one controls this "option". How do you decide not to persist? Or to clear? Or selectively persist some collections and not others? It may be in the code but people shouldn't have to read the code to learn about such an important feature. You didn't describe how this works in an update to README or other docs. If you fork, you'll want to do that.

Finally, It's not too hard to implement persistence yourself without modifying this library by extending your implementation of the InMemoryDbService that defines your DB (a la HeroInMemDataService and HeroInMemDataOverrideService). Just add methods that save and restore the db from wherever. Then inject this service where you will and call those methods. If you want to persist "automagically", intercept the request/response pipeline and stash the db object when and as you like. Not as nice as if this library did it for you but the flexibility is there.

In light of the fact that no action is likely on this PR, I must reluctantly close it. But not without first telling you how much I appreciate your putting this PR together. It's a worthy idea. It took care and effort and I hate to see it unrewarded.

I hope this library continues to be useful to you. And I wish you the best.