isolating side effects

70 views
Skip to first unread message

Brian Craft

unread,
Apr 14, 2013, 5:37:39 PM4/14/13
to clj-...@googlegroups.com
In the examples I've seen, view functions directly reference model functions, which directly reference databases. I expect this makes it difficult to test the view functions, or to operate on multiple databases. Are there any common patterns for isolating these things, especially the db access? If view functions took a context, for example, they could be pure functions. But I'm not sure how the context would be passed.

Linus Ericsson

unread,
Apr 15, 2013, 5:57:48 AM4/15/13
to clj-...@googlegroups.com
pedestal.io adresses this problem to some extent by sort-of an automata pattern, check it out! otherwise its common to mock ring-requests.

I share your confusion over this.

/L


On Sunday, April 14, 2013, Brian Craft wrote:
In the examples I've seen, view functions directly reference model functions, which directly reference databases. I expect this makes it difficult to test the view functions, or to operate on multiple databases. Are there any common patterns for isolating these things, especially the db access? If view functions took a context, for example, they could be pure functions. But I'm not sure how the context would be passed.

--
You received this message because you are subscribed to the Google Groups "clj-noir" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clj-noir+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Tomasz Lipski

unread,
Apr 15, 2013, 12:38:25 PM4/15/13
to clj-...@googlegroups.com
On Sunday, April 14, 2013 11:37:39 PM UTC+2, Brian Craft wrote:
In the examples I've seen, view functions directly reference model functions, which directly reference databases. I expect this makes it difficult to test the view functions, or to operate on multiple databases. Are there any common patterns for isolating these things, especially the db access? If view functions took a context, for example, they could be pure functions. But I'm not sure how the context would be passed.

Hi, 

You might want to see the approach used by me in Ganelon micro-framework (http://ganelon.tomeklipski.com/basics#concepts):

  • Widget is a function, returning part of the DOM tree, referenceable by an id attribute. Whole page can be built from standard content (e.g. menubar) and widgets, which hold the presentation logic.
  • Action is a standard Ring handler, which returns JSON operations. The action is a place to communicate with business services or persistence layers and can be be referenced from Widgets or even JavaScript code.
  • Operation is a JSON object, which is interpreted by browser-side JavaScript plugins. 
I am not saying, that you have to use Ganelon with your app to test it properly - but that approach might inspire you for some kind of separation between logic and presentation.

The micro-framework is not Noir based itself - although it was in first versions, before Noir was discontinued :).

Best regards,

Tomek Lipski
Reply all
Reply to author
Forward
0 new messages