These are chat archives for synrc/n2o

30th
Nov 2016
Sébastien Saint-Sevin
@seb3s
Nov 30 2016 11:53
Hello
a question here
wf:q(Source)
I fail to get the value when Source is a binary.
Isn't better if it would be possible ?
Namdak Tonpa
@5HT
Nov 30 2016 15:26
I remember it was like that long before
Sébastien Saint-Sevin
@seb3s
Nov 30 2016 15:31
you mean it should function ?
Namdak Tonpa
@5HT
Nov 30 2016 15:40
The code from n2o/samples
code() -> case wf:q(<<"code">>) of undefined  -> "../privacy.htm";
                                    Code -> wf:to_list(wf:depickle(Code)) end.
Sébastien Saint-Sevin
@seb3s
Nov 30 2016 15:52
in my code I 've got
Volume = wf:q(erlang:iolist_to_binary(["volume_", Id])),
that returns undefined
whereas
Volume = wf:q(wf:f("volume_~b", [toi(Id)])),
returns the correct value
why ?
Namdak Tonpa
@5HT
Nov 30 2016 17:18
maybe binary q is for url params and list/atom q is for nitrogen elements
Sébastien Saint-Sevin
@seb3s
Nov 30 2016 17:19
yep, hence my point was to add the binary possibility for nitrogen elements as well
in addition to list/atom
Namdak Tonpa
@5HT
Nov 30 2016 17:20
converting binary key to list/atom will announce API breakage
Sébastien Saint-Sevin
@seb3s
Nov 30 2016 17:21
I would do it the other way : store binary keys and allow list/atom that can be converted to binary with no pb
Namdak Tonpa
@5HT
Nov 30 2016 17:22
render_ev(#ev{module=M,name=F,msg=P,trigger=T},_Source,Linked,State) ->
    case F of
         api_event -> M:F(P,Linked,State);
         event -> lists:map(fun({K,V})-> put(K,wf:to_binary(V)) end,Linked), M:F(P);
         _UserCustomEvent -> M:F(P,T,State) end.
Sébastien Saint-Sevin
@seb3s
Nov 30 2016 17:22
yes, could be :
Namdak Tonpa
@5HT
Nov 30 2016 17:23
here is population of element params to process dictionary
Sébastien Saint-Sevin
@seb3s
Nov 30 2016 17:23
put(wf:to_binary(K),wf:to_binary(V))
and wf:q() then converts key to binary as well to retrieve the value as for qc
should not break the api
what do you think ?
Namdak Tonpa
@5HT
Nov 30 2016 17:25
I'm ok with it but we should ask @m-2k too
personally me dislike nitrogen model to access parameters
when I tried to systemize it I leave it as it is mostly because it is a pure mess :-)
so I even agree on total rework in this area
Sébastien Saint-Sevin
@seb3s
Nov 30 2016 17:27
:-)
Namdak Tonpa
@5HT
Nov 30 2016 17:28
most users would like to see explicit unpacking params from state
like to introduce event/2 API with open #ctx
event({protocol,Message},{ctx,param1,param2}) -> ...
and perform wf:get(Ctx, Key)
wf:send, wf:get, wf:put, kvs:get, kvs:put do it more like modern effect systems
any protocol can be runned on a set of states, etc, ..
states are directly connected with KVS schema, etc
I had even prototypes of such approach
somewhere inside n2o repo, need to see history
1.9
render_ev(#ev{module=Controller,name=Action,msg=P,trigger=T}=Ev,Source,Linked,State) ->
    case Controller:Action(Ev,State#cx{params=Linked}) of
         {json,Dictionary,NewState} -> {wf:json(Dictionary),NewState};
         {binary,Raw,NewState} -> {{binary,Raw},NewState};
         {actions,Elements,NewState} ->
              {wf:json([{eval,iolist_to_binary(
                      n2o_nitrogen:render_actions(wf:actions()))}]), NewState};
         {file,FileName,NewState} -> {<<>>,NewState};
         {redirect,Address,NewState} -> {<<>>,NewState};
         _ -> {<<>>,State}
    end.
aka Rails endpoint
Controller:Action(Ev,State#cx{params=Linked})
but this is wrong too
#cx should be a part of persisted model
with direct access to parameter by offset not by dictionary key