This repository has been archived by the owner on May 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
odarriba
reviewed
Apr 16, 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." |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
odarriba
approved these changes
Apr 28, 2018
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 themark_as_read/2
function in thenotification
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.