Why are multi-methods not working as functions for Reagent/Re-frame?

前端 未结 4 1148
粉色の甜心
粉色の甜心 2021-02-12 12:53

In a small app I\'m building that uses Reagent and Re-frame I\'m using multi-methods to dispatch which page should be shown based on a value in the app state:

(d         


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-12 13:27

    The first problem that jumps out at me is that your methods take no arguments:

    (defmethod layout/pages :register [] [register-page])
                                      ^ arglist
    

    Here you have an empty arglist, but presumably you'll be calling this multimethod with one or two arguments (since its dispatch function is a keyword and keywords can be called with one or two arguments).

    If you want to call this multimethod with a single argument and just ignore it inside the body of the :register method, change the above to

    (defmethod layout/pages :register [_] [register-page])
                                       ^ argument to be ignored
    

    Also, I expect you'll probably want to call pages yourself like you previously did (that is, revert the change to square brackets that you mentioned in the question).


    This may or may not fix the app – there may be other problems – but it should get you started. (The multimethod will definitely not work with those empty arglists if you pass in any arguments.)

提交回复
热议问题