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

Basic protocol support for vanilla JS objects via mori.extend #108

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

tgriesser
Copy link
Contributor

Adds basic support for extending several protocols to vanilla JS objects via mori.extend

The protocols included thusfar: IAssociative, ICloneable, ICollection, ICounted, IEncodeClojure, IEncodeJS, IEquiv, IHash, IKVReduce, ILookup, IMap, ISeq, ISeqable

Real world use case: https://github.com/tgriesser/mori-cursors

Currently, adding a protocol looks something like:

mori.extend("IAssociative", Cursor.prototype, {
  contains_key: Cursor.prototype.contains_key,
  assoc: Cursor.prototype.assoc
})

However I'm wondering whether it'd be more concise to assume the object provided as the second arg to extend implements specific protocol functions, so you could just say:

mori.extend("IAssociative", MapCursor.prototype, 'contains_key', 'assoc')

or just

mori.extend("IAssociative", MapCursor.prototype)

Also, the IEncodeClojure is currently pretty useless, but would become useful with the proposed change here (or similar): http://dev.clojure.org/jira/browse/CLJS-842

@tgriesser
Copy link
Contributor Author

Updated the entry point as mentioned tgriesser@c46eb42#commitcomment-7496107

@eborden
Copy link

eborden commented Sep 15, 2014

Hey guys, is this pull request scheduled for a merge at any point?

@swannodette
Copy link
Owner

@eborden it needs to be updated to be a bit more flexible.

@tgriesser
Copy link
Contributor Author

Any specific pointers on what I could do to update it? It's been working quite well for me (aside from the js->clj issue - http://dev.clojure.org/jira/browse/CLJS-842)

@eborden
Copy link

eborden commented Dec 20, 2014

I'm currently using tgriesser's patch and it is working quite nicely. I'm also curious what added flexibility you see a need for.

@skrat
Copy link

skrat commented Jan 16, 2015

@swannodette it looks pretty solid to me, and given that it allows @tgriesser to implement cursors, seems good enough reason to include this PR. Looking at your recent benchmarks against immutable.js, it makes want to make the switch, but... no cursors, no go for us.

@tgriesser
Copy link
Contributor Author

@swannodette went ahead and updated with master if you wanted to take another look.

@skrat the "cursors" I implemented in that gh repo are definitely subpar and I'm not really planning on maintaining them. So I'm not sure I'd recommend using that implementation in anything serious, but it does demonstrate a proof of concept of using custom persistent data structures from mori which is pretty neat.

@skrat
Copy link

skrat commented Jan 27, 2015

I wonder whether a library that exposes ClojureScript's atom and Om's cursors wouldn't be a better solution, that way the maintenance problem would be solved by having a simple wrapper. The meat would be implemented in well established and actively maintained projects.

@eborden
Copy link

eborden commented Jan 27, 2015

@skrat This PR has other uses other than implementing cursors, such as utilizing complex types in Maps and Sets.

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

Successfully merging this pull request may close these issues.

4 participants