Skip to content
This repository has been archived by the owner on May 22, 2020. It is now read-only.

Dispatch actions on runtime #3

Merged
merged 10 commits into from
Apr 29, 2018
Merged

Dispatch actions on runtime #3

merged 10 commits into from
Apr 29, 2018

Conversation

crbelaus
Copy link
Contributor

Currently, Frankt defines a handle_in/3 function in the Channel for every available action. This caused the Channel to grow with every new action, creating a compile dependency between every action (changing a Frankt action triggered a recompilation of the Channel, which in turn recompiled every other Frankt action even if it is unrelated to the one initially changed).

This pull request aims to fix this issue by dispatching Frankt actions on runtime. The action notification:mark_as_read will now be dispatched as a call to the mark_as_read/2 function in the notification handler module.
The correspondency between handler names such as notification and the Elixir module that implements the Frankt actions is configured by the user and can vary from channel to channel.

This PR also deprecates the use of handle_in/3 to implement Frankt actions and switches to basic Elixir functions. This change has the benefit of following the common Elixir conventions for function calling and dispatching, including the possibility of easily pattern match and use guard clauses to choose between clauses of the same function depending on the received parameters.

The next steps before releasing 1.0 would be finishing the documentation (#1) and adding automatic tests (#2).

The changes in this PR have been running in production for more than two months. This is why the PR contains some other improvements in the JS code.

crbelaus and others added 7 commits January 13, 2018 20:26
Previously Frankt defined a `handle_in/3` function for every available
action. This caused the channel exposing the Frankt actions to grow
with lots of clauses for the same function.

Frankt now dispatches actions in runtime to their corresponding modules.
The “notification:mark_as_read” action will now be dispatched by
invoking the “mark_as_read” function in the configured “notification”
module.

The correspondency between handler names such as “notification” and the
corresponding modules is configured by the user and can vary from 
channel to channel.
@crbelaus crbelaus added this to the v1.0.0 milestone Mar 24, 2018
@crbelaus crbelaus self-assigned this Mar 24, 2018
lib/frankt.ex Outdated
def __execute_action__(module, fun, params, socket, gettext) do
invoke_action = fn ->
unless function_exported?(module, fun, 2) do
raise "Frankt is trying to execute an action, but the handler module does not define the appropriate function. Please define a '#{fun}/3' function in your ·#{module} module."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be /2?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

@crbelaus crbelaus merged commit 921f2c0 into master Apr 29, 2018
@crbelaus crbelaus deleted the runtime-dispatch branch April 29, 2018 19:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants