Fixed incorrect env resolution for querie

This commit is contained in:
Julien Eluard 2018-10-14 17:56:19 +02:00
parent c502b85fe7
commit 374bba614d
No known key found for this signature in database
GPG Key ID: 6FD7DB5437FCBEF6
3 changed files with 5 additions and 15 deletions

View File

@ -1,10 +1,11 @@
(ns pluto.components.html) (ns pluto.components.html
(:require [re-frame.core :as re-frame]))
(defn view [props & content] (defn view [props & content]
(into [:div props] content)) (into [:div props] content))
(defn button [{:keys [on-click]} & content] (defn button [{:keys [on-click]} & content]
(into [:button {:on-click on-click}] content)) (into [:button {:on-click #(re-frame/dispatch on-click)}] content))
(defn text [props & content] (defn text [props & content]
(into [:span props] content)) (into [:span props] content))

View File

@ -4,7 +4,6 @@
(:refer-clojure :exclude [resolve]) (:refer-clojure :exclude [resolve])
(:require [clojure.string :as string] (:require [clojure.string :as string]
[clojure.set :as set] [clojure.set :as set]
[re-frame.core :as re-frame]
[pluto.reader.errors :as errors] [pluto.reader.errors :as errors]
[pluto.reader.reference :as reference])) [pluto.reader.reference :as reference]))

View File

@ -1,6 +1,5 @@
(ns pluto.reader.views (ns pluto.reader.views
(:require [clojure.spec.alpha :as spec] (:require [clojure.spec.alpha :as spec]
[re-frame.core :as re-frame]
[pluto.reader.blocks :as blocks] [pluto.reader.blocks :as blocks]
[pluto.reader.destructuring :as destructuring] [pluto.reader.destructuring :as destructuring]
[pluto.reader.errors :as errors] [pluto.reader.errors :as errors]
@ -9,9 +8,6 @@
[pluto.reader.types :as types] [pluto.reader.types :as types]
[pluto.utils :as utils])) [pluto.utils :as utils]))
;; TODO Distinguish views (can contain blocks, symbols) validation
;; from hiccup validation (view after parsing) that are pure hiccup
(spec/def ::form (spec/def ::form
(spec/or (spec/or
:string string? :string string?
@ -41,7 +37,7 @@
(defn- resolve-component [ctx o] (defn- resolve-component [ctx o]
(cond (cond
(fn? o) o (fn? o) o ;; TODO better abstract blocks
(symbol? o) (get-in ctx [:capacities :components o :value]))) (symbol? o) (get-in ctx [:capacities :components o :value])))
(defmulti resolve-default-component-properties (defmulti resolve-default-component-properties
@ -54,17 +50,11 @@
(defmethod resolve-default-component-properties :default [_ value] (defmethod resolve-default-component-properties :default [_ value]
nil) nil)
(defn resolve-existing-component-property-type [ctx ext type v]
(let [{:keys [data errors] :as t} (types/resolve ctx ext type v)]
(if (= :event type)
(errors/merge-errors {:data #(re-frame/dispatch data)} errors)
t)))
(defn resolve-custom-component-properties [ctx ext component k v] (defn resolve-custom-component-properties [ctx ext component k v]
(if-let [type (get-in ctx [:capacities :components component :properties k])] (if-let [type (get-in ctx [:capacities :components component :properties k])]
(if-not (and (types/reference-types type) (not= :event type)) (if-not (and (types/reference-types type) (not= :event type))
;; TODO Infer symbol types and fail if type does not match ;; TODO Infer symbol types and fail if type does not match
(if (symbol? v) v (resolve-existing-component-property-type ctx ext type v)) (if (symbol? v) v (types/resolve ctx ext type v))
{:errors [(errors/error ::errors/invalid-component-property-type {:component component :property k :type type})]}) {:errors [(errors/error ::errors/invalid-component-property-type {:component component :property k :type type})]})
{:errors [(errors/error ::errors/unknown-component-property {:component component :property k})]})) {:errors [(errors/error ::errors/unknown-component-property {:component component :property k})]}))