Lonestar ElixirConf 2017- KEYNOTE: Phoenix 1.3 by Chris McCord

By: Confreaks

383   2   25089

Uploaded on 02/28/2017

Lonestar Elixir 2017- KEYNOTE: Phoenix 1.3 by Chris McCord

Chris McCord is a programmer with a passion for science and building things. He spends his time crafting the Phoenix Framework, working with the fine folks at DockYard, writing books like Metaprogramming Elixir, and teaching others the tools of the trade.

Comments (4):

By anonymous    2017-09-20

The context module allows us to remove Repo calls from the controller to their own module, so that there can be separation between concerns.

For more, try listening to this talk by Chris McCord:

https://www.youtube.com/watch?v=tMO28ar0lW8&index=1&list=PLE7tQUdRKcyaMEekS1T32hUw19UxzqBEo

and check out the comments in Phoenix code:

https://github.com/phoenixframework/phoenix/blob/07f1bbc7627117adc23ec8355a88465859e4302d/lib/mix/tasks/phx.gen.context.ex

Original Thread

By anonymous    2017-09-20

The significant difference with phoenix.gen.json and phx.gen.json is the context module. It is a concept of "Bounded Context" from Domain-Driven Design.

The context is an Elixir module that serves as an API boundary for the given resource. A context often holds many related resources. Therefore, if the context already exists, it will be augmented with functions for the given resource. Note a resource may also be split over distinct contexts (such as Accounts.User and Payments.User).

(https://hexdocs.pm/phoenix/Mix.Tasks.Phx.Gen.Json.html)

In your case, you generated an API context module in lib/my_app/api/api.ex.

You may want to rename to API context module to something like Content.

== Compilation error in file lib/my_app_web/views/content_asset_view.ex ==
** (CompileError) lib/my_app_web/views/content_asset_view.ex:2: module MyAppWeb is not loaded and could not be found
    (elixir) expanding macro: Kernel.use/2
    lib/my_app_web/views/content_asset_view.ex:2: MyAppWeb.ContentAssetView (module)
    (elixir) lib/kernel/parallel_compiler.ex:121: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/1

Based on your error message, most likely the module MyAppWeb is not defined.

For more learning resource about context:

https://www.youtube.com/watch?v=tMO28ar0lW8&feature=youtu.be&t=12m21s

https://martinfowler.com/bliki/BoundedContext.html

http://phoenixframework.org/blog/phoenix-1-3-0-released

Original Thread

Submit Your Video

If you have some great dev videos to share, please fill out this form.