This file contains hidden or 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
const MIN_FONT_SIZE = 24; | |
function drawTextElement(ctx, text, fontSize) { | |
const scale = fontSize / MIN_FONT_SIZE; | |
if (scale <= 1) { | |
ctx.scale(scale, scale) | |
ctx.drawImage(getTexture(text), 0, 0); | |
} else { | |
drawText(ctx, text, fontSize) | |
} | |
} |
This file contains hidden or 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
<MapPosition> | |
<DragBox> | |
<SVGLine | |
path={pathFromCoordinates( | |
element.coords, | |
viewport | |
)} /> | |
</DragBox> | |
<SelectionFrame | |
polygon={selectionFramePolygon(element.coords, viewport)} /> |
This file contains hidden or 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
children = [ | |
MyApp.Repo, | |
MyAppWeb.Telemetry, | |
{Phoenix.PubSub, name: MyApp.PubSub}, | |
MyAppWeb.Endpoint, | |
MyApp.PresenceDrainer # <-- NEW! | |
] |
This file contains hidden or 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
defmodule MyApp.PresenceDrainer do | |
use GenServer | |
require Logger | |
def start_link(opts \\\\ []) do | |
GenServer.start_link(__MODULE__, opts, name: __MODULE__) | |
end | |
@impl GenServer | |
def init(_init_arg) do |
This file contains hidden or 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
defmodule MyApp.GracefulShutdownHandler do | |
use GenServer | |
require Logger | |
def start_link(opts \\\\ []) do | |
GenServer.start_link(__MODULE__, opts, name: __MODULE__) | |
end | |
@impl GenServer | |
def init(_init_arg) do |
This file contains hidden or 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
defmodule MyHandler do | |
use ChannelHandler.Handler | |
plug MyPlug when action in [:create, :delete] | |
plug MyPlug when event in ["post:delete"] | |
def create(payload, context, socket) do | |
# ... | |
end | |
end |
This file contains hidden or 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
defmodule Felt.Channels.LayerHandler do | |
use ChannelHandler | |
def handle_in("create", payload, context, socket) do | |
# Create a layer | |
end | |
end |
This file contains hidden or 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
defmodule Felt.Channels.ElementHandler do | |
# This brings useful Phoenix channels imports, even if you're not | |
# using the router | |
use ChannelHandler.Handler | |
def create(payload, context, socket) do | |
# Create the element | |
end | |
def update(payload, context, socket) do |
This file contains hidden or 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
defmodule Felt.Channels.MapChannel do | |
use ChannelHandler.Router | |
def join(_topic, _payload, socket) do | |
{:ok, socket} | |
end | |
router do | |
plug &Plugs.ensure_authenticated/4 |
This file contains hidden or 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
defmodule Felt.Channels.ElementHandler do | |
def handle_event(event, payload, socket) when event in ["create", "update", "delete"] do | |
plugs = [ | |
&ensure_authenticated/4, | |
&ensure_map_editable/4, | |
{&check_feature_flag/4, :element_importing} | |
] | |
with {:cont, socket, payload, bindings} <- ChannelHandler.process_plugs(plugs, socket, payload) do | |
do_handle_event(event, socket, payload, bindings) |