Skip to content
This repository has been archived by the owner on May 29, 2023. It is now read-only.

Commit

Permalink
More work on the demo
Browse files Browse the repository at this point in the history
This time, we have a little signup form that mocks some async effectful
interaction to show what it would look like to make an AJAX request or
whatever. Still adding things to the "standard library" as I realise
they're invaluable, a long way off polished.
  • Loading branch information
Tom Harding committed Jul 9, 2018
1 parent cb8f285 commit 52dfe22
Show file tree
Hide file tree
Showing 13 changed files with 407 additions and 145 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"prepublish": "bower install",
"pscid": "pscid",
"tags": "purs docs --format ctags './**/*.purs' > tags",
"test": "pulp run -I test -m Test.Main"
"test": "pulp build -I test -m Test.Main --to test/dist.js"
},
"devDependencies": {
"jsdom": "^11.11.0"
Expand Down
8 changes: 4 additions & 4 deletions src/Panda.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ module Panda
, runApplicationInBody
) where

import Data.Maybe (Maybe(..), maybe)
import Data.Traversable (traverse)
import Data.Maybe (Maybe(..))
import Effect (Effect)
import FRP.Event (Event) as FRP
import Panda.Bootstrap (bootstrap)
import Panda.Internal.Types (Component, Updater, ShouldUpdate(..)) as ExportedTypes
import Panda.Internal.Types (Component, Updater) as ExportedTypes
import Web.DOM.Internal.Types (Node) as Web
import Web.DOM.Node (appendChild) as Web
import Web.Event.Event (Event, preventDefault) as ExportedTypes
import Web.HTML (window) as Web
import Web.HTML.HTMLDocument (body, toDocument) as Web
import Web.HTML.HTMLElement (toNode) as Web
Expand All @@ -19,7 +19,7 @@ import Web.HTML.Window (document) as Web
import Prelude

-- | When a component has been rendered, the following controlls will be
-- | returned.
-- | returned.

type Controller input output
= { destroy Effect Unit
Expand Down
9 changes: 6 additions & 3 deletions src/Panda/Bootstrap.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Panda.Bootstrap
) where

import Control.Alt ((<|>))
import Data.Maybe (maybe)
import Effect.Ref as Ref
import Web.DOM.Internal.Types (Node) as Web
import Web.DOM.Document (Document) as Web
Expand Down Expand Up @@ -35,7 +36,7 @@ bootstrap document { view, subscription, initial, update } = do
stateRef ← Ref.new initial.state
external ← FRP.create

let
let
events FRP.Event message
events = subscription <|> system.events

Expand All @@ -48,10 +49,12 @@ bootstrap document { view, subscription, initial, update } = do
-- with the state at that moment.
{ message, state } # update external.push \callback → do
mostRecentState ← Ref.read stateRef

let new@{ state } = callback mostRecentState
Ref.write new.state stateRef

Ref.write state stateRef
system.handleUpdate new
new.input # maybe (pure unit) \input →
system.handleUpdate { input, state }

system.handleUpdate initial

Expand Down
29 changes: 18 additions & 11 deletions src/Panda/Builders/Properties.purs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module Panda.Builders.Properties
( module Producers
, module Watchers
( module Watchers
, module Producers

, FormEncodingType (..)
, Target (..)

, accept
, accesskey
, action
, align
, alt
Expand Down Expand Up @@ -112,7 +113,8 @@ import Panda.Internal.Types as Types
import Panda.Builders.Property.Producers as Producers
import Panda.Builders.Property.Watchers as Watchers

import Prelude ((<<<))
import Data.String.CodeUnits (singleton)
import Prelude ((<<<))

-- | A fully-polymorphic property.

Expand All @@ -132,6 +134,9 @@ make key setting
accept String StaticProperty
accept = make "accept"

accesskey Char StaticProperty
accesskey = make "accesskey" <<< singleton

action String StaticProperty
action = make "action"

Expand All @@ -144,10 +149,8 @@ alt = make "alt"
async String StaticProperty
async = make "async"

autocomplete Boolean StaticProperty
autocomplete
= make "autocomplete"
<<< if _ then "on" else "off"
autocomplete String StaticProperty
autocomplete = make "autocomplete"

autofocus String StaticProperty
autofocus = make "autofocus"
Expand Down Expand Up @@ -224,8 +227,10 @@ defer = make "defer"
dirname String StaticProperty
dirname = make "dirname"

disabled String StaticProperty
disabled = make "disabled"
disabled Boolean StaticProperty
disabled
= make "disabled"
<<< if _ then "disabled" else ""

download String StaticProperty
download = make "download"
Expand Down Expand Up @@ -365,8 +370,10 @@ readonly = make "readonly"
rel String StaticProperty
rel = make "rel"

required String StaticProperty
required = make "required"
required Boolean StaticProperty
required
= make "required"
<<< if _ then "required" else ""

reversed String StaticProperty
reversed = make "reversed"
Expand Down
1 change: 1 addition & 0 deletions src/Panda/Builders/Property/Watchers.purs
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ when predicate build
if predicate update
then Types.SetTo (build update)
else Types.Ignore

2 changes: 2 additions & 0 deletions src/Panda/HTML.purs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module Panda.HTML
( module Builders
, module Exports

, delegate
) where

import Data.Maybe (Maybe)
Expand Down
21 changes: 15 additions & 6 deletions src/Panda/Internal/Types.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import Control.Alternative ((<|>))
import Control.Plus (empty)
import Data.Algebra.Array as Algebra.Array
import Data.Foldable (foldl)
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show (genericShow)
import Data.Maybe (Maybe)
import Data.String as String
import Effect (Effect)
import FRP.Event (Event) as FRP
import Web.Event.Internal.Types (Event) as DOM
Expand All @@ -20,9 +17,20 @@ import Prelude
-- | you have input/output/message/state wrong or mixed up.

type Updater input output message state
= (output Effect Unit)
((state { input input, state state }) Effect Unit)
{ message message, state state }
= ( output Effect Unit )

( ( state
{ input Maybe input
, state state
}
)
Effect Unit
)

{ message message
, state state
}

Effect Unit

-- | A component in Panda is a unit capable of running as an independent
Expand Down Expand Up @@ -187,6 +195,7 @@ derive instance eqProducer ∷ Eq Producer

-- | Convert a Producer to its html attribute name.

producerToAttribute Producer String
producerToAttribute = case _ of
OnBlur"blur"
OnChange"change"
Expand Down
2 changes: 1 addition & 1 deletion src/Panda/Property.purs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ module Panda.Property
-- | by proxy.

import Panda.Builders.Properties as Builders
import Panda.Internal.Types (Producer(..), Property(..)) as ExportedTypes
import Panda.Internal.Types ( Producer(..), Property(..), ShouldUpdate(..)) as ExportedTypes
1 change: 0 additions & 1 deletion src/Panda/Render/Property.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module Panda.Render.Property where
import Control.Plus (empty)
import Data.Foldable (traverse_)
import Data.Maybe (Maybe(..))
import Data.String (drop, toLower)
import Effect (Effect)
import Effect.Ref as Ref
import FRP.Event (create, subscribe) as FRP
Expand Down
84 changes: 0 additions & 84 deletions test/Example/Form.purs

This file was deleted.

Loading

0 comments on commit 52dfe22

Please sign in to comment.