Fork me on GitHub
#hoplon
<
2016-05-10
>
piotrek20:05:13

Hi, what’s the best practice for handling parameters to defelem? Should I always design my elements to accept only cell parameters or maybe I should expect that sometimes it will be plain value or sometimes a cell?

dm320:05:56

@piotrek: depends on the case. All of the parameters could be cells, but that doesn't always make sense in practice. Usually I find that there's at least one cell in the attributes of my defelems - a state or something like that. No hard rules here

piotrek20:05:01

@dm3: so when I create an element and I expect that sometimes it would be good to pass a plain value (it would be simpler at the usage place) and sometimes a cell, how should I handle such parameter in my element?

piotrek20:05:34

Like this? (let [attr (if (cell? attr) attr (cell attr))] …)?

dm320:05:51

yeah, I try to avoid cases like this

piotrek20:05:00

so I can handle it as it would always be a cell no matter if someone passed me a plain value?

dm320:05:30

I usually have either/either

dm320:05:00

think it simplifies the API a bit

piotrek20:05:03

dm3: thanks