Open nelsonic opened 4 years ago
cd assets & elm init
We should now have a elm.json
file and a src
folder in assets where our Elm code will be added
Phoenix is already using Webpack to create one javascript containing all the code imported in assets/js/app.js
There is a specific webpack loader for Elm: https://github.com/elm-community/elm-webpack-loader that we can use in our Phoenix project to compile and bundle the Elm application
install the Elm loader. Make sure you are still on the assets folder as it is where the package.json
is defined and install elm-webpack-loader with npm:
cd /assets
npm install --save-dev elm-webpack-loader
add a new rule in /assets/webpack.config.js
to use the elm loader to bundle the .elm files:
{
test: /\.elm$/,
exclude: [/elm-stuff/, /node_modules/],
use: {
loader: 'elm-webpack-loader',
options: {
optimize: true
}
}
To test that Elm is working well with Phoenix and webpack we can create a simple application:
Main.elm
file in `assets/src with the following code:
module Main exposing (main)
import Html exposing (text)
main = text "This is Elm text!"
- Import the Elm application in `/assets/js/app.js`:
```js
// import Elm application
import { Elm } from "../src/Main.elm";
var app = Elm.Main.init({
node: document.getElementById('elm-app')
})
Create the div html node where the Elm application will be added, for example in lib/app_web/templates/layout/app.html.eex
we can add in the body:
<div id="elm-app"></div>
<script type="text/javascript" src="<%= Routes.static_path(@conn, "/js/app.js") %>"></script
You can now run the Phoenix application with mix phx.server
and you should be able to see "This is Elm text!".
You can add changes to the Elm code, Phoenix will automatically detect the modificaiton in app.js and reload the page
We do not yet have any collaborative or team features in our App (as we're focussing on the solo experience) however we hypothesize that capturing thoughts, securely sharing them with relevant people (e.g: team or family members) and collaborating on getting things done are the "killer features" that people/teams/orgs will be willing to pay for if we build great UX.
Objectives
Our key objectives are:
Todo
Presence
so that we can see a list of the Avatars of the people who are online/offline.people
schema andsession
controller similar to what we have in the MVPpeople
table so that we can displayperson.picture
in UI.JS
toElm
(practice for us and a good intro to Elm for the Community)google-auth-phoenix-presence.md
The file does not have to be prosaic it can just be a list of the steps taken (I will write it up later!) i.e. we aren't interested in just the "end result" we want to know exactly how it was done. If you're in any doubt what step-by-step instructions look like, see: /todo-list-javascript-tutorial The point of a Spike1 is to share the knowledge acquired with the team (and in our case the wider @dwyl community)Bonus Level
1https://en.wikipedia.org/wiki/Spike_(software_development)