Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.prototype #1150

Closed
nick-thompson opened this issue Dec 15, 2013 · 6 comments
Closed

.prototype #1150

nick-thompson opened this issue Dec 15, 2013 · 6 comments

Comments

@nick-thompson
Copy link
Contributor

None of our constructors use .prototype, and I'm not really sure why. For one, this is a pretty big performance hit for any application using several databases (i.e. our test suite?). For two, there's a lot of poorly written, nested functions within constructors for the sake of closed variables that makes reading/understanding the files so much harder than it needs to be (sorry if I'm being harsh, but the LevelPouch constructor in our leveldb adapter is... the entire file).


Want to back this issue? Place a bounty on it! We accept bounties via Bountysource.

@daleharvey
Copy link
Member

The main reason for using the module pattern is that I find it less readable to read code constantly refering to this, and especially since we use a lot of async api's internally leading to a lot of var self = this (or .bind(this)).

Its slightly less performant but only if you are recreating the object a lot of time which is a fairly special case for our tests, not much reason for users code to do that.

If theres a proposal thats cleaner than the alternative then down for checking it out, in theory I would expect a full switch to .prototype to be less readable though

@calvinmetcalf
Copy link
Member

I agree with you @nick-thompson, though actually doing it is the hard part. @daleharvey while this. can be confusing, at the moment our solution is not much better. for instance use of this would allow us to further modulerize the code e.g. break up lib/setup.js and also the adapters could inherit from Pouch.adapter.

It actually might not be that hard, changing this line to var api = this; and then deleting this line would do it for http adapters

@nick-thompson
Copy link
Contributor Author

I'll take a stab at rewriting the leveldb adapter to conform to this proposal and we can carry on this discussion in the context of actual code, sound good? I'll probably get to it some time tomorrow or Tuesday. Also, I'm working on writing up some thoughts about how we can minimize the amount of code an adapter actually requires, so perhaps I'll include those thoughts in my example rewrite and we can hash both things out at once.

@calvinmetcalf
Copy link
Member

fyi the map reduce plugin uses prototype

@enquora
Copy link

enquora commented Jan 2, 2014

Agree with @nick-thompson on the problem of grokking code given multiple levels of nested callbacks in the absence of any design documents at all, especially statecharts. This seems certain to negatively affect implementation of correct behaviour.

calvinmetcalf added a commit that referenced this issue Feb 23, 2014
calvinmetcalf added a commit that referenced this issue Feb 23, 2014
calvinmetcalf added a commit that referenced this issue Feb 23, 2014
calvinmetcalf added a commit that referenced this issue Feb 23, 2014
calvinmetcalf added a commit that referenced this issue Feb 23, 2014
calvinmetcalf added a commit that referenced this issue Feb 24, 2014
@daleharvey
Copy link
Member

Done

sygi pushed a commit to sygi/pouchdb that referenced this issue Apr 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants