-
-
Notifications
You must be signed in to change notification settings - Fork 309
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
add IEntityMap marker protocol #4
Conversation
It's useful to be able to differentiate entity maps from plain maps. This patch uses `specify!` to mark the returned maps as entity maps.
:cardinality -> :db/cardinality and :many -> :db.cardinality/many. Support :db/valueType :db.type/ref in the schema. Change entity so that refs are followed. Update README and tests.
I always was curious—what’s the grand idea behind marker protocols? I understand ordinary protocols, e.g. when something is ISequable, you can call |
@tonsky Marker protocols are extremely useful - we now know that the map came from a DataScript database. For example you could imagine in Om being able to call |
Sorry, I don’t get it. Ok I have IEntityMap. What if I assoc? What if I dissoc? Why I cannot transact with map that come not from DB? For me, entity is just a map. You can put any map to database. It doesn’t matter where it comes from. We shouldn’t treat some maps different from others and build any expectations on that. Especially when it’s as invisible as marker protocols are. |
@tonsky entities from the database simply need to be marked (think about If you don't want to add things like this I will go ahead with starting a separate client side Datomic-like effort with the properties that I believe are needed. |
@tonsky I think the idea here isn't about changing how DataScript treats records that are received in transactions, but about enabling third-party libraries to change their behaviour when interacting with data queried from the DB. Om manages application state by wrapping values in 'cursors'. Right now there are cursor implementations for standard maps and vectors, and calling Without the marker protocol, Om will just treat entities from DataScript as plain maps. They'll get wrapped in a standard map cursor, and any time |
@robknight Data queried from DB is just data. It may come from What you say about Om cursors can be very easily implemented without such a strange thing as “marker protocols”, in a very straightforward way: by providing an implementation for DataScript entity cursor:
I know how Om implements cursors (I wrote official wiki doc about them), but for me it always seemed like a lot of unnecessary magic. It’s too fragile, hard to understand and has questionable user experience (now it’s cursor, now it’s not). Reliance of Om for third-party libraries to implement marker protocols is just a sign that something is wrong about that design. It’s easy to fix them, though: just make cursors explicit, like atoms or refs are explicit. Atoms do not pretend to work like a map or a vector. They are not ILookup nor ISequential. They are containers with two operations: get value from it and put value inside. If cursors worked that way, it’d be much easier to understand and work with them. @swannodette what do you think? |
@tonsky marker protocols are not strange Cursors are a useful underlying concrete implementation of an abstraction, but they were designed such that if some better underlying concrete implementation came along users could migrate to that implementation with zero headache. Exposed cursors prevents flexibility to move to some other more appropriate underlying implementation - whether that's entity maps, bound queries, etc. etc. So while it may seem like "magic" this is actually an important tradeoff I'm not going to give up on yet. It's not by coincidence that internally Om relies very little on the implementation details of cursors. You've done a great job blazing a trail with DataScript, however I have some ideas of my own how the code should actually be implemented and I've ended up starting on my own effort. Thanks much! |
I won’t merge IEntityMap. |
DataScript 0.3.0 now has lazy entities type & supports |
It's useful to be able to differentiate entity maps from plain
maps. This patch uses
specify!
to mark the returned maps as entitymaps.