Coder Social home page Coder Social logo

m-renaud / elm-scaffolding Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 0.0 12 KB

Provides a basic directory structuring for Elm projects using best practices.

License: BSD 3-Clause "New" or "Revised" License

CSS 7.46% HTML 31.39% Elm 57.81% Shell 3.34%

elm-scaffolding's Introduction

Elm Scaffolding

A basic separation-by-feature directory structure for Elm projects inspired by the Elm Architecture Tutorial and Kris Jenkins' How I Structure Elm Apps which I encourage everyone to read.

How to use

Clone the repository and remove the existing .git directory, you'll want to start with a clean slate for your project.

git clone https://github.com/m-renaud/elm-scaffolding.git \
&& rm -rf elm-scaffolding/.git \
&& cd elm-scaffolding && git init

Once you do this you'll also want to go through and update the elm-package.json to point to your repository.

Building

./build

This builds your application and places it and all necessary resources into the dist/ subdirectory.

Styling

By default the scoffolding only links the css defined at assets/style.css, but you may want to use a frontend framework. To use Material Design Lite or Bootstrap uncomment the relevant section in src/index.html and follow the instructions there.

Directory Layout

All of the source code for the app lives in the src/ directory and the css, external JavaScript, and media live in the assets/ directory. Lets dig a bit deeper into the source directory.

Each module is broken up into 4 main files Types.elm, State.elm, View.elm, and Rest.elm.

Types: The Model and Msg types.

State: The init, subscriptions, and update function.

View: The view function.

Rest: The REST APIs and JSON decoders. Not every module will have this.

This pattern will repeat at the top level of your app as well for each of your modules. For small modules you may chose to combine these into a single file, that's up to you.

scr/App.elm

This is the entrypoint into your Elm application. This module doesn't contain anything except the main function that will be invoked from your src/index.html. All this file does is glue together your initial state, update function, subscriptions, and top level view.

import State
import View


main : Program Never
main =
    Html.App.program
        { init = State.init
        , update = State.update
        , subscriptions = State.subscriptions
        , view = View.view
        }

src/Types.elm

Contains the top level Model and Msg types for your app. Your Model will typically consist of the models of the submodules of your application as we'll see later on. The message type will be a union type containing the messages of your modules and any application level messages that you have.

src/View.elm

Contains the top level view function for your app which sets up the high level layout, leaving specifics to the view function of modules.

src/State.elm

The init, upate, and subscriptions functions at the top level of your app end up being mostly boilerplate to invoke the corresponding functions on each of the modules and wrap them with the appropriate message type. This will also be the case if you have modules that contain other module, this file should give you a good idea of how to handle the composition.

elm-scaffolding's People

Contributors

m-renaud avatar

Stargazers

Kevin avatar Tann avatar Ariel Weingarten avatar OldhamMade avatar  avatar Alex Kurkin avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.