Skip to content

Commit

Permalink
fix: try captured function this way
Browse files Browse the repository at this point in the history
  • Loading branch information
thecristen committed May 8, 2024
1 parent 2c21257 commit 8e920f5
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/dotcom/realtime_schedule.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ defmodule Dotcom.RealtimeSchedule do
@predicted_schedules_per_stop 2

@default_opts [
stops_fn: {@stops_repo, :get, 1},
stops_fn: Function.capture(@stops_repo, :get, 1),
routes_fn: &RoutesRepo.by_stop_with_route_pattern/1,
predictions_fn: &PredictionsRepo.all_no_cache/1,
schedules_fn: &SchedulesRepo.by_route_ids/2,
Expand Down
2 changes: 1 addition & 1 deletion lib/dotcom/trip_plan/itinerary_row.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defmodule Dotcom.TripPlan.ItineraryRow do
@type trip_mapper :: (Schedules.Trip.id_t() -> Schedules.Trip.t() | nil)
@type alerts_repo :: (DateTime.t() -> [Alerts.Alert.t()] | nil)

defstruct stop_mapper: {@stops_repo, :get_parent, 1},
defstruct stop_mapper: Function.capture(@stops_repo, :get_parent, 1),
route_mapper: &Routes.Repo.get/1,
trip_mapper: &Schedules.Repo.trip/1,
alerts_repo: &Alerts.Repo.all/1
Expand Down
2 changes: 1 addition & 1 deletion lib/dotcom/trip_plan/map.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule Dotcom.TripPlan.Map do
@stops_repo Application.compile_env!(:dotcom, :repo_modules)[:stops]
@default_opts [
route_mapper: &Routes.Repo.get/1,
stop_mapper: {@stops_repo, :get_parent, 1}
stop_mapper: Function.capture(@stops_repo, :get_parent, 1)
]

@moduledoc """
Expand Down
5 changes: 4 additions & 1 deletion lib/dotcom/trip_plan/related_link.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ defmodule Dotcom.TripPlan.RelatedLink do
icon_name: nil

@stops_repo Application.compile_env!(:dotcom, :repo_modules)[:stops]
@default_opts [route_by_id: &Routes.Repo.get/1, stop_by_id: {@stops_repo, :get_parent, 1}]
@default_opts [
route_by_id: &Routes.Repo.get/1,
stop_by_id: Function.capture(@stops_repo, :get_parent, 1)
]

import Phoenix.HTML.Link, only: [link: 2]
# Need a view in order to use the components. Ideally we'd have a separate
Expand Down
6 changes: 5 additions & 1 deletion lib/dotcom_web/controllers/schedule/line.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ defmodule DotcomWeb.ScheduleController.Line do

@type t :: %__MODULE__{
stops_by_route_fn:
{Application.compile_env!(:dotcom, :repo_modules)[:stops], :by_route, 3}
Function.capture(
Application.compile_env!(:dotcom, :repo_modules)[:stops],
:by_route,
3
)
}
end

Expand Down
5 changes: 3 additions & 2 deletions lib/stops/nearby.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ defmodule Stops.Nearby do
@type route_with_direction :: %{direction_id: 0 | 1 | nil, route: Route.t()}

defmodule Options do
@stops_repo Application.compile_env!(:dotcom, :repo_modules)[:stops]

@moduledoc "Defines shared options and defaults for this module's functions."
defstruct api_fn: &Stops.Nearby.api_around/2,
keys_fn: &Stops.Nearby.keys/1,
fetch_fn:
{Application.compile_env!(:dotcom, :repo_modules)[:stops], :get_parent, 1},
fetch_fn: Function.capture(@stops_repo, :get_parent, 1),
routes_fn: &Routes.Repo.by_stop_and_direction/2,
limit: nil
end
Expand Down

0 comments on commit 8e920f5

Please sign in to comment.