Giter VIP home page Giter VIP logo

Comments (2)

ikitommi avatar ikitommi commented on May 28, 2024

Interesting. All schemas run both :decode and :encode in children in same order. I also think this is wrong. I need to revisit the ordering, thanks for reporting.

Tested with a dirty (and invalid) fix:

diff --git a/src/malli/core.cljc b/src/malli/core.cljc
index d66b3f9..a2b3b1e 100644
--- a/src/malli/core.cljc
+++ b/src/malli/core.cljc
@@ -519,7 +519,8 @@
 (defn -parent-children-transformer [parent children transformer method options]
   (let [parent-transformer (-value-transformer transformer parent method options)
         child-transformers (into [] (keep #(-transformer % transformer method options)) children)
-        child-transformer (when (seq child-transformers) (apply -comp (rseq child-transformers)))]
+        mapper (if (= :encode method) identity rseq)
+        child-transformer (when (seq child-transformers) (apply -comp (mapper child-transformers)))]
     (-intercepting parent-transformer child-transformer)))

.. which gives "correct" order/results for this case but doesn't solve the whole problem.

from malli.

ikitommi avatar ikitommi commented on May 28, 2024

Documenting to myself, current order on decode:

(let [log (atom [])
      log! (fn [s p] (fn [x] (swap! log conj [(:i (m/properties s)) p]) x))]
  (m/decode
   [:map {:i 0}
    [:x {:i 1} [:int {:i 2}]]
    [:y {:i 3} [:string {:i 4}]]
    [:z {:i 5} [:maybe {:i 6} [:and {:i 7}
                               [:keyword {:i 8}]
                               [:or {:i 9}
                                [:string {:i 10}]
                                [:qualified-keyword {:i 11}]]]]]]
   {:x 1
    :y "kikka"
    :z :kikka/kukka}
   (mt/transformer
    {:default-decoder {:compile (fn [schema _]
                                  {:enter (log! schema :enter)
                                   :leave (log! schema :leave)})}}))
  @log)
;[[0 :enter]
; [1 :enter]
; [2 :enter]
; [2 :leave]
; [1 :leave]
; [3 :enter]
; [4 :enter]
; [4 :leave]
; [3 :leave]
; [5 :enter]
; [6 :enter]
; [7 :enter]
; [8 :enter]
; [8 :leave]
; [9 :enter]
; [10 :enter]
; [10 :leave]
; [11 :enter]
; [11 :leave]
; [9 :leave]
; [7 :leave]
; [6 :leave]
; [5 :leave]
; [0 :leave]]

from malli.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.