move handling of anonymous handlers to gen_json
This commit is contained in:
parent
29175a7845
commit
e145220d92
2 changed files with 13 additions and 9 deletions
|
@ -24,13 +24,18 @@
|
|||
-module(gen_json).
|
||||
|
||||
-export([behaviour_info/1]).
|
||||
-export([parser/2, parser/3]).
|
||||
-export([parser/1, parser/2, parser/3]).
|
||||
-export([handle_event/2, init/1]).
|
||||
|
||||
|
||||
behaviour_info(callbacks) -> [{init, 0}, {handle_event, 2}];
|
||||
behaviour_info(_) -> undefined.
|
||||
|
||||
|
||||
parser(F) -> parser(F, []).
|
||||
|
||||
parser(F, Opts) when is_function(F, 1) -> parser(?MODULE, {F, undefined}, Opts);
|
||||
parser({F, State}, Opts) when is_function(F, 2) -> parser(?MODULE, {F, State}, Opts);
|
||||
parser(Mod, Args) -> parser(Mod, Args, []).
|
||||
|
||||
parser(Mod, Args, Opts) when is_atom(Mod), is_list(Opts) ->
|
||||
|
@ -44,3 +49,9 @@ parser(Mod, Args, Opts) when is_atom(Mod), is_list(Opts) ->
|
|||
; decoder ->
|
||||
fun(Input) -> (jsx:decoder(Mod, Args, Opts))(Input) end
|
||||
end.
|
||||
|
||||
|
||||
handle_event(Event, {F, undefined}) -> F(Event), {F, undefined};
|
||||
handle_event(Event, {F, State}) -> {F, F(Event, State)}.
|
||||
|
||||
init(State) -> State.
|
|
@ -26,7 +26,6 @@
|
|||
-export([parse_opts/1, extract_opts/1]).
|
||||
-export([nice_decimal/1]).
|
||||
-export([json_escape/2]).
|
||||
-export([handle_event/2, init/1]).
|
||||
|
||||
-include("../include/jsx_opts.hrl").
|
||||
|
||||
|
@ -267,12 +266,6 @@ to_hex(X) -> X + 48. %% ascii "1" is [49], "2" is [50], etc...
|
|||
|
||||
|
||||
|
||||
handle_event(Event, {F, undefined}) -> F(Event), {F, undefined};
|
||||
handle_event(Event, {F, State}) -> {F, F(Event, State)}.
|
||||
|
||||
init(State) -> State.
|
||||
|
||||
|
||||
%% eunit tests
|
||||
-ifdef(TEST).
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue