Skip to content

Use div-root; fix examples' warnings #286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Bugfixes:

Other improvements:
- Drop requirement that module name be `Main` (#285 by @JordanMartinez)
- Fixes compiler warnings in examples (#286 by @JordanMartinez)
- Support cookbook repo UI recipes by adding element to `frame.html` (#286 by @JordanMartinez)

## [v2022-07-12.1](https://github.com/purescript/trypurescript/releases/tag/v2022-07-12.1)

Expand Down
1 change: 1 addition & 0 deletions client/examples/ADTs.purs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ derive instance ordName :: Ord Name
phoneBook :: Map Name String
phoneBook = singleton (Name "John" "Smith") "555-555-1234"

main :: Effect Unit
main = render =<< withConsole do
logShow (lookup (Name "John" "Smith") phoneBook)
3 changes: 2 additions & 1 deletion client/examples/DoNotation.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Control.MonadPlus (guard)
import Effect.Console (logShow)
import Data.Array ((..))
import Data.Foldable (for_)
import TryPureScript
import TryPureScript (render, withConsole)

-- Find Pythagorean triples using an array comprehension.
triples :: Int -> Array (Array Int)
Expand All @@ -16,5 +16,6 @@ triples n = do
guard $ x * x + y * y == z * z
pure [x, y, z]

main :: Effect Unit
main = render =<< withConsole do
for_ (triples 20) logShow
1 change: 1 addition & 0 deletions client/examples/Generic.purs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ instance eqPerson :: Eq Person where
instance ordPerson :: Ord Person where
compare = genericCompare

main :: Effect Unit
main = render =<< withConsole do
logShow $ Person
{ first: "John"
Expand Down
1 change: 1 addition & 0 deletions client/examples/Loops.purs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Data.Array ((..))
import Data.Foldable (for_)
import TryPureScript (render, withConsole)

main :: Effect Unit
main = render =<< withConsole do
for_ (10 .. 1) \n -> log (show n <> "...")
log "Lift off!"
1 change: 1 addition & 0 deletions client/examples/Operators.purs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ infixl 5 subdirectory as </>
filepath :: FilePath
filepath = "usr" </> "local" </> "bin"

main :: Effect Unit
main = render =<< withConsole do
log filepath
1 change: 1 addition & 0 deletions client/examples/QuickCheck.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Data.Array (sort)
import Test.QuickCheck (quickCheck, (===))
import TryPureScript (render, withConsole, h1, h2, p, text)

main :: Effect Unit
main = do
render $ h1 $ text "QuickCheck"
render $ p $ text """QuickCheck is a Haskell library which allows us to assert properties
Expand Down
2 changes: 2 additions & 0 deletions client/examples/Records.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import Effect.Console (log)
import TryPureScript (render, withConsole)

-- We can write functions which require certain record labels...
showPerson :: forall r. { firstName :: String, lastName :: String | r } -> String
showPerson o = o.lastName <> ", " <> o.firstName

-- ... but we are free to call those functions with any
-- additional arguments, such as "age" here.
main :: Effect Unit
main = render =<< withConsole do
log $ showPerson
{ firstName: "John"
Expand Down
1 change: 1 addition & 0 deletions client/examples/Recursion.purs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ isEven :: Int -> Boolean
isEven 0 = true
isEven n = isOdd (n - 1)

main :: Effect Unit
main = render =<< withConsole do
logShow $ isEven 1000
logShow $ isEven 1001
1 change: 1 addition & 0 deletions client/examples/TypeClasses.purs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ printf = printfWith ""
debug :: String -> Int -> String -> String
debug uri status msg = printf "[" uri "] " status ": " msg

main :: Effect Unit
main = render =<< withConsole do
log $ debug "http://www.purescript.org" 200 "OK"
log $ debug "http://bad.purescript.org" 404 "Not found"
1 change: 1 addition & 0 deletions client/public/frame.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@
</head>
<body>
<main id="main"></main>
<div id="root"></div>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not totally following why this is required. Is the cookbook unable to use main id="main"? If not, and it seems important that we specifically use <div id="root">, then can we adjust the existing code (ie. the TryPureScript rendering) to point at this div and remove <main id="main">? It's a bit odd to have both.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

main is used to redirect Console.log (when under a TryPureScript.render =<< TryPureScript.withConsole, so that the strings logged to the console are instead added as nodes under the main id="main" HTML element rather than logging to the web browser's console.

I don't want the two to mix, so I'm creating a separate element for React usage.

</body>
</html>