Skip to content
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

Allow equals-field to be translated & more #21

Open
SevereOverfl0w opened this issue Nov 24, 2015 · 3 comments
Open

Allow equals-field to be translated & more #21

SevereOverfl0w opened this issue Nov 24, 2015 · 3 comments

Comments

@SevereOverfl0w
Copy link

equals-field relies on a new agreement: multiple selectors!

Unfortunately, this is not supported by translate-errors, which assumes that you've gone through attr

I imagine the solution would be to make a selector be run against a "map-if-vector" in translate-errors or enforce that all selectors must be a list, and then update the translation for equals-field to pull first-selector and second-selector from the vector

Alternatively, any key matching *selector (or that's in a supplied vector?) could be translated, that could work too... and would allow for multiple in a different sense (I could equals-field to any field)

@SevereOverfl0w
Copy link
Author

Looks like you favour the vector format: dpom@881eecc#commitcomment-4802492

@SevereOverfl0w
Copy link
Author

Let's try again with the actual issue I am seeing, because I've misreported.

assign-names doesn't work for the various different selector fields provided (:selector, :first-selector, etc.) I propose that we come up with a way to support these various selector fields!

@SevereOverfl0w
Copy link
Author

I've got my own alternative implementation of assign-names, I've used a slightly different style to yours, but I'm still not happy with my implementation.

(defn- selector
  [field]
  (re-matches #"(.*)selector" (name field)))

(defn find-selectors
  [key-list]
  (->> key-list
       (map selector)
       (filter (fn [[x]] x))
       (map (fn [[w p]] [(keyword w) p]))))

(defn name-for
  [prefix]
  (keyword (str prefix "name")))

(defn assign-name
  [e fields]
  (apply merge
    (let [selectors (find-selectors (keys e))]
      (map (fn [[keyname prefix]]
             (let [name-key (name-for prefix)]
              (assoc e name-key (fields (keyname e)))))
        selectors))))

(defn alt-assign-names
  [errors fields]
  (map #(assign-name % fields) errors))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant