Skip to content

Schema cursor validation issue #24

@vseguip

Description

@vseguip

Hello I attach the following minimal test case:


(ns pvhmi.core
  (:import [goog.dom query])
  (:require-macros [cljs.core.async.macros :refer [go]]
                   [schema.macros :as sm])
  (:use [jayq.core :only [$]])
  (:require [om.core :as om :include-macros true]
            [om.dom  :include-macros true]
            [clojure.data :as data]
            [clojure.string :as string]
            [om-tools.schema :as schema]
            [schema.core :as s]
            [om-tools.core :refer-macros [defcomponent defcomponentk]]
            [om-tools.dom :as dom :include-macros true]))


(sm/defrecord V [x :- s/Int 
                 y :- s/Int])

(def Simple 
  {s/Keyword V})

(def Composed 
  {:vecs Simple})

(def Data (atom {:vecs {:a (V. 1 2) :b (V. 3 4)}}))

(defcomponent child
  [v :- Simple owner]
  (render-state [this state]
                (dom/div nil
                         (dom/h3 nil "Child Results")
                         (if-let [err (s/check (schema/cursor Simple) v)] (dom/h4 nil (str "Error validating child cursor: " err)) (dom/h4 "Success validating child cursor"))
                         (if-let [err (s/check Simple v)] (dom/h4 nil (str "Error validating child cursor vs value: " err)) (dom/h4 "Success validating child cursor"))
                         (if-let [err (s/check Simple (.-value v))] (dom/h4 nil (str "Error validating child value: " err)) (dom/h4 "Success validating child value"))) ))

(defcomponent parent
  [d :- Composed owner]
  (render-state [this state]
     (dom/div nil
              (dom/h1 nil "Parent results")
              (if-let [err (s/check (schema/cursor Composed) d)] (dom/h2 nil (str "Error validating parent cursor: " err)) (dom/h2 "Success validating parent cursor"))
              (if-let [err (s/check Composed d)] (dom/h2 nil (str "Error validating parent cursor vs value: " err)) (dom/h2 "Success validating parent cursor"))

              (if-let [err (s/check  Composed (.-value d))] (dom/h2 nil (str "Error validating parent value: " err)) (dom/h2 "Success validating parent value"))

                (om/build child (:vecs d)) )))


(om/root
 parent
 Data
 {:target (. js/document (getElementById "main"))
  })

Project dependencies:

 :dependencies [[org.clojure/clojure "1.5.1"]
                 [org.clojure/clojurescript "0.0-2227"]
                 [org.clojure/core.async "0.1.267.0-0d7780-alpha"]
                 [jayq "2.5.1"]
                 [om "0.6.4"]
                 [com.cemerick/clojurescript.test "0.3.1"]
                 [prismatic/om-tools "0.2.2"]
                 ]

This renders the following page

Parent results

Error validating parent cursor: {:vecs {:a (not (instance? pvhmi.core/V #pvhmi.core.V{:x 1, :y 2})), :b (not (instance? pvhmi.core/V #pvhmi.core.V{:x 3, :y 4}))}}

Error validating parent cursor vs value: {:vecs {:a (not (instance? pvhmi.core/V #pvhmi.core.V{:x 1, :y 2})), :b (not (instance? pvhmi.core/V #pvhmi.core.V{:x 3, :y 4}))}}

Success validating parent value

Child Results

Error validating child cursor: {:a (not (instance? pvhmi.core/V #pvhmi.core.V{:x 1, :y 2})), :b (not (instance? pvhmi.core/V #pvhmi.core.V{:x 3, :y 4}))}

Error validating child cursor vs value: {:a (not (instance? pvhmi.core/V #pvhmi.core.V{:x 1, :y 2})), :b (not (instance? pvhmi.core/V #pvhmi.core.V{:x 3, :y 4}))}

Success validating child value

Which seems counterintuitive to me. I would expect the first and third if-let to succeed and the middle one to fail. However it seems to fail whenever trying to validate a cursor. What am I doing wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions