Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b8e6f9b
Basic TOC and descriptions
javcasas Jan 27, 2017
76362eb
Properly visible bullet points
javcasas Jan 27, 2017
1f0e54d
Starting to word it
javcasas Feb 3, 2017
bb6088d
Basic metadata
javcasas Feb 3, 2017
99ca73a
Mark TODOs
javcasas Feb 3, 2017
c04d361
URLs
javcasas Feb 3, 2017
1943083
A bit more of text.
javcasas May 5, 2017
f1e9c42
Some progress
javcasas May 9, 2017
f03b704
Image
javcasas May 19, 2017
355c48b
Image
javcasas May 19, 2017
a32c875
More images
javcasas May 19, 2017
9288925
Adding code and fixed frontend
javcasas May 19, 2017
eb00cce
More content
javcasas May 24, 2017
989123a
More details
javcasas Jun 23, 2017
4b6f103
Remove todos
javcasas Jun 23, 2017
6d0b9e6
Review comments
javcasas Jun 23, 2017
2ff28f7
More review comments
javcasas Jun 23, 2017
bc4e4a5
Trying to get the right colouring on shell snippets
javcasas Jun 23, 2017
f1c2d80
Prototyping links
javcasas Jun 23, 2017
f686da8
Links
javcasas Jun 23, 2017
e5db8eb
Links, links everywhere
javcasas Jun 23, 2017
2a7e2ec
Fix links
javcasas Jun 23, 2017
31e3024
Comments
javcasas Jun 28, 2017
823c67c
Code
javcasas Jun 28, 2017
87fe098
Proper reference to code
javcasas Jun 28, 2017
17d5706
We
javcasas Jun 28, 2017
c8e1898
Wording
javcasas Jun 28, 2017
12c000a
Minor typographical changes
jsl Jul 12, 2017
7307ea2
More gender-neutral text
jsl Jul 12, 2017
1ebfab5
Merge pull request #52 from stackbuilders/jsl-minor-changes
javcasas Jul 13, 2017
e628fb5
Merge branch 'connecting_haskell_backend_to_purescript_frontend' of s…
javcasas Jul 13, 2017
f1bf8e4
Remove boilerplate on stack.yaml
javcasas Jul 13, 2017
fb78b3e
Guys -> Folks
javcasas Jul 13, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
backend/.stack-work/
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# purescript-bridge Tutorial
This tutorial shows how to use purescript-bridge
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright Author Stack Builders (c) 2017

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* Neither the name of Stack Builders nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Main where

import Lib

main :: IO ()
main = startApp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: backend
version: 0.1.0.0
synopsis: Initial project template from stack
description: Please see README.md
homepage: https://github.com/githubuser/backend#readme
license: BSD3
license-file: LICENSE
author: Author name here
maintainer: example@example.com
copyright: 2017 Author name here
category: Web
build-type: Simple
extra-source-files: README.md
cabal-version: >=1.10

library
hs-source-dirs: src
exposed-modules: Lib
, Types
build-depends: base >= 4.7 && < 5
, aeson
, servant-server
, wai
, wai-cors
, warp
default-language: Haskell2010

executable backend-exe
hs-source-dirs: app
main-is: Main.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends: base
, backend
default-language: Haskell2010

executable bridge
hs-source-dirs: bridge
main-is: Main.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends: base
, backend
, purescript-bridge
default-language: Haskell2010

test-suite backend-test
type: exitcode-stdio-1.0
hs-source-dirs: test
main-is: Spec.hs
build-depends: base
, backend
ghc-options: -threaded -rtsopts -with-rtsopts=-N
default-language: Haskell2010

source-repository head
type: git
location: https://github.com/githubuser/backend
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Main where

import Types (Scientist)
import Language.PureScript.Bridge (writePSTypes, buildBridge, defaultBridge, mkSumType)
import Data.Proxy (Proxy(..))

main :: IO ()
main = writePSTypes "../frontend/src" (buildBridge defaultBridge) myTypes
where
myTypes = [ mkSumType (Proxy :: Proxy Scientist)
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
module Lib
( startApp
) where

import Data.Aeson
import Data.Aeson.TH
import Network.Wai
import Network.Wai.Handler.Warp
import Servant
import Network.Wai.Middleware.Cors
import Types (Scientist, scientists)

type API = "scientist" :> Get '[JSON] [Scientist]

startApp :: IO ()
startApp = do
putStrLn "Starting"
run 8080 app
putStrLn "Finished"

app :: Application
app = simpleCors (serve api server)

api :: Proxy API
api = Proxy

server :: Server API
server = return scientists
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE DeriveGeneric #-}
module Types where

import Data.Aeson
import Data.Aeson.TH
import GHC.Generics (Generic)

data Scientist = Scientist
{
sNames :: [String]
, sPhotoUrl :: String
} deriving (Eq, Show, Generic)

$(deriveJSON defaultOptions ''Scientist)

scientists :: [Scientist]
scientists = [ Scientist ["Isaac", "Newton"] "https://upload.wikimedia.org/wikipedia/commons/3/39/GodfreyKneller-IsaacNewton-1689.jpg"
, Scientist ["Albert", "Einstein"] "https://upload.wikimedia.org/wikipedia/commons/d/d3/Albert_Einstein_Head.jpg"
, Scientist ["Gottfried", "Wilhelm", "Leibniz"] "http://apusepress.booktype.pro/early-readings-in-the-philosophy-of-science/gottfried-wilhelm-leibniz-1646-1716/static/Leibniz.jpg"
, Scientist ["Stephen", "Hawking"] "https://upload.wikimedia.org/wikipedia/commons/e/eb/Stephen_Hawking.StarChild.jpg"
, Scientist ["Pythagoras"] "http://www.thefamouspeople.com/profiles/images/pythagoras-4.jpg"
, Scientist ["Wernher", "von", "Braun"] "https://upload.wikimedia.org/wikipedia/commons/5/56/Wernher_von_Braun_1960.jpg"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
resolver: lts-7.17
packages:
- '.'
extra-deps: []
flags: {}
extra-package-dbs: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
main :: IO ()
main = putStrLn "Test suite not yet implemented"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules/
bower_components/
output/
dist/
static/dist
.psci_modules
npm-debug.log
**DS_Store
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Copyright (c) 2016, Alexander C. Mingoia
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the <organization> nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Basic Proof of Concept for purescript-bridge

This is a basic Proof-of-concept frontend for a functional fullstack app.
Based on [Pux-starter-app](https://github.com/alexmingoia/pux-starter-app).

See the [Tutorial](https://www.stackbuilders.com/tutorials/functional-full-stack/purescript-bridge/) for more context on how to use this.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "pux-starter-app",
"homepage": "https://github.com/alexmingoia/pux-starter-app",
"authors": [
"Alex Mingoia <talk@alexmingoia.com>"
],
"description": "Starter Pux application using webpack with hot-reloading.",
"main": "support/index.js",
"license": "BSD3",
"dependencies": {
"purescript-pux": "^7.0.0",
"purescript-pux-devtool": "^4.1.0",
"purescript-affjax": "^3.0.2",
"purescript-argonaut-codecs": "^2.1.0",
"purescript-argonaut-generic-codecs": "5.2.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "pux-starter-app",
"version": "9.0.0",
"description": "Starter Pux application using webpack with hot-reloading.",
"main": "support/index.js",
"keywords": [
"pux",
"purescript-pux",
"boilerplate",
"starter-app"
],
"scripts": {
"postinstall": "bower cache clean && bower install",
"clean": "rimraf static/dist && rimraf dist && rimraf output",
"build": "npm run clean && webpack --config ./webpack.production.config.js --progress --profile --colors",
"watch": "npm run clean && node ./webpack.config.js",
"serve": "http-server static --cors -p 3000",
"start": "npm run watch",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git://github.com/alexmingoia/pux-starter-app.git"
},
"author": "Alexander C. Mingoia",
"license": "BSD-3-Clause",
"bugs": {
"url": "https://github.com/alexmingoia/pux-starter-app/issues"
},
"dependencies": {
"bower": "^1.7.9",
"connect-history-api-fallback": "^1.2.0",
"express": "^4.13.4",
"html-webpack-plugin": "^2.15.0",
"http-server": "^0.9.0",
"purescript": "^0.10.1",
"purescript-psa": "^0.3.9",
"purs-loader": "^2.0.0",
"react": "^15.0.0",
"react-dom": "^15.0.0",
"rimraf": "^2.5.2",
"webpack": "^2.1.0-beta.25"
},
"devDependencies": {
"source-map-loader": "^0.1.5",
"webpack-dev-middleware": "^1.8.3",
"webpack-hot-middleware": "^2.12.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module App.Counter where

import Prelude ((+), (-), const, show)
import Pux.Html (Html, div, span, button, text)
import Pux.Html.Events (onClick)

data Action = Increment | Decrement

type State = Int

init :: State
init = 0

update :: Action -> State -> State
update Increment state = state + 1
update Decrement state = state - 1

view :: State -> Html Action
view state =
div
[]
[ button [ onClick (const Increment) ] [ text "Increment" ]
, span [] [ text (show state) ]
, button [ onClick (const Decrement) ] [ text "Decrement" ]
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module App.Layout where

import App.Counter as Counter
import App.Scientist as Scientist
import App.NotFound as NotFound
import App.Routes (Route(Home, NotFound))
import Prelude (($), map)
import Pux.Html (Html, div, h1, p, text)

data Action
= ScientistAction (Scientist.Action)
| ScientistsLoaded (Scientist.State)
| PageView Route
| Nop

type State =
{ route :: Route
, sScientists :: Scientist.State }

init :: State
init =
{ route: Home
, sScientists: Scientist.init }

update :: Action -> State -> State
update (PageView route) state = state { route = route }
update (ScientistAction action) state = state { sScientists = Scientist.update action state.sScientists }
update (ScientistsLoaded s) state = state { sScientists = s }
update Nop state = state

view :: State -> Html Action
view state =
div
[]
[ h1 [] [ text "Scientist Viewer" ]
, case state.route of
Home -> map ScientistAction $ Scientist.view state.sScientists
NotFound -> NotFound.view state
]
Loading