-
-
Save julienfantin/26cacfda7fc9192a3ed5942534d934ca to your computer and use it in GitHub Desktop.
Om.next tempids reconciliation for a remote mutation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns om-next.remote-merge | |
(:require | |
[om.next :as om])) | |
;; The code below simulates: | |
;; | |
;; - an optimistic insert that uses a tempid | |
;; - merging the remote response with tempids map | |
;; | |
;; It tries to check whether the tempids get properly replaced by the ones | |
;; contained in the server-response. | |
;; | |
;; In actuality this whole behavior below would be kicked off by: | |
;; | |
;; (om/transact! | |
;; reconciler | |
;; `[(~'auth/register | |
;; {:db/id ~(om/tempid) | |
;; :user/email "foo@bar", | |
;; :user/password "___"})]) | |
(let [temp-id :temp | |
real-id :real | |
;; App state after optimistic update | |
;; | |
initial-state {:current-user [:db/id temp-id], | |
:db/id {temp-id | |
{:db/id temp-id, :user/email "foo@bar" :user/password "___"}}} | |
;; The remote query response our send fn gets from the parser (c.f. issue #1) | |
;; | |
server-response {'auth/register | |
{:result | |
{:tempids {[:db/id temp-id] [:db/id real-id]}}}} | |
;; State expected after the remote result is merged | |
;; | |
expected-state {:current-user [:db/id real-id], | |
:db/id {real-id | |
{:db/id real-id, :user/email "foo@bar" :user/password "___"}}} | |
reconciler (om/reconciler {:state initial-state :db-key :db/id}) | |
_ (om/merge! reconciler server-response)] | |
@(om/app-state reconciler)) | |
;; => | |
;; {:current-user [:db/id :temp], | |
;; :db/id {:temp {:db/id :temp, :user/email "foo@bar", :user/password "___"}}, | |
;; auth/register {:result {:tempids {[:db/id :temp] [:db/id :real]}}}, | |
;; :om.next/tables #{}} | |
;; Issues: | |
;; 1. The tempids in the `server-response` above never make it to the `migrate` | |
;; function. If the send function "lifts" the tempids one level in the map, i.e. | |
;; | |
;; {'auth/register | |
;; {:result {} | |
;; :tempids {[:db/id temp-id] [:db/id real-id]}}} | |
;; | |
;; then `migrate` does get the tempids map, but the app state ends up as: | |
;; | |
;; #:om.next{:tables #{}} | |
;; 2. The entire response ends up assoc'd into the state? | |
;; 3. `default-migrate` doesn't seem to try and replace links. How is | |
;; `:current-user` not supposed to become a dangling ref? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment