Unverified Commit b1d32b37 authored by Justin Woo's avatar Justin Woo Committed by GitHub

Merge pull request #5 from poorscript/updates

updates
parents 1699fa41 f7f6403a
...@@ -13,17 +13,17 @@ ...@@ -13,17 +13,17 @@
"author": "James Laver", "author": "James Laver",
"license": "MPL-2.0", "license": "MPL-2.0",
"devDependencies": { "devDependencies": {
"karma": "^4.1.0", "karma": "^4.4.1",
"karma-chrome-launcher": "^2.2.0", "karma-chrome-launcher": "^3.1.0",
"karma-cli": "^2.0.0", "karma-cli": "^2.0.0",
"karma-mocha": "^1.3.0", "karma-mocha": "^1.3.0",
"mocha": "^6.0.0", "mocha": "^7.0.0",
"psc-package": "^3.0.1", "psc-package": "^3.0.1",
"pulp": "^13.0.0", "pulp": "^13.0.0",
"purescript": "^0.13.5", "purescript": "^0.13.5",
"purs-loader": "^3.2.0",
"@testing-library/react": "^8.0.1", "@testing-library/react": "^8.0.1",
"spago": "^0.8.5" "spago": "^0.8.5",
"purs-loader": "^3.7.1"
}, },
"dependencies": { "dependencies": {
"react": "^16.8.6", "react": "^16.8.6",
......
{-
Welcome to Spacchetti local packages!
Below are instructions for how to edit this file for most use
cases, so that you don't need to know Dhall to use it.
## Warning: Don't Move This Top-Level Comment!
Due to how `dhall format` currently works, this comment's
instructions cannot appear near corresponding sections below
because `dhall format` will delete the comment. However,
it will not delete a top-level comment like this one.
## Use Cases
Most will want to do one or both of these options:
1. Override/Patch a package's dependency
2. Add a package not already in the default package set
This file will continue to work whether you use one or both options.
Instructions for each option are explained below.
### Overriding/Patching a package
Purpose:
- Change a package's dependency to a newer/older release than the
default package set's release
- Use your own modified version of some dependency that may
include new API, changed API, removed API by
using your custom git repo of the library rather than
the package set's repo
Syntax:
Replace the overrides' "{=}" (an empty record) with the following idea
The "//" or "⫽" means "merge these two records and
when they have the same value, use the one on the right:"
-------------------------------
let override =
{ packageName =
upstream.packageName ⫽ { updateEntity1 = "new value", updateEntity2 = "new value" }
, packageName =
upstream.packageName ⫽ { version = "v4.0.0" }
, packageName =
upstream.packageName // { repo = "https://www.example.com/path/to/new/repo.git" }
}
-------------------------------
Example:
-------------------------------
let overrides =
{ halogen =
upstream.halogen ⫽ { version = "master" }
, halogen-vdom =
upstream.halogen-vdom ⫽ { version = "v4.0.0" }
}
-------------------------------
### Additions
Purpose:
- Add packages that aren't alread included in the default package set
Syntax:
Replace the additions' "{=}" (an empty record) with the following idea:
-------------------------------
let additions =
{ "package-name" =
mkPackage
[ "dependency1"
, "dependency2"
]
"https://example.com/path/to/git/repo.git"
"tag ('v4.0.0') or branch ('master')"
, "package-name" =
mkPackage
[ "dependency1"
, "dependency2"
]
"https://example.com/path/to/git/repo.git"
"tag ('v4.0.0') or branch ('master')"
, etc.
}
-------------------------------
Example:
-------------------------------
let additions =
{ benchotron =
mkPackage
[ "arrays"
, "exists"
, "profunctor"
, "strings"
, "quickcheck"
, "lcg"
, "transformers"
, "foldable-traversable"
, "exceptions"
, "node-fs"
, "node-buffer"
, "node-readline"
, "datetime"
, "now"
]
"https://github.com/hdgarrood/purescript-benchotron.git"
"v7.0.0"
}
-------------------------------
-}
let mkPackage = let mkPackage =
https://raw.githubusercontent.com/purescript/package-sets/psc-0.13.5-20191127/src/mkPackage.dhall sha256:0b197efa1d397ace6eb46b243ff2d73a3da5638d8d0ac8473e8e4a8fc528cf57 https://raw.githubusercontent.com/purescript/package-sets/ea2423043df6c90f0de754977923b6c5dfdddcfc/src/mkPackage.dhall sha256:0b197efa1d397ace6eb46b243ff2d73a3da5638d8d0ac8473e8e4a8fc528cf57
let upstream = let upstream =
https://raw.githubusercontent.com/purescript/package-sets/psc-0.13.5-20191127/src/packages.dhall sha256:654e8427ff1f9830542f491623cd5d89b1648774a765520554f98f41d3d1b3b3 https://github.com/purescript/package-sets/releases/download/psc-0.13.5-20200103/packages.dhall sha256:0a6051982fb4eedb72fbe5ca4282259719b7b9b525a4dda60367f98079132f30
let overrides =
{ contravariant =
mkPackage
[ "newtype", "either", "prelude", "tuples" ]
"https://github.com/purescript/purescript-contravariant"
"v4.0.1"
, ordered-collections =
mkPackage
[ "arrays"
, "foldable-traversable"
, "gen"
, "lists"
, "maybe"
, "partial"
, "prelude"
, "st"
, "tailrec"
, "tuples"
, "unfoldable"
, "unsafe-coerce"
]
"https://github.com/purescript/purescript-ordered-collections.git"
"v1.6.1"
}
let additions = let additions =
{ dom-simple = { dom-simple =
...@@ -152,7 +18,7 @@ let additions = ...@@ -152,7 +18,7 @@ let additions =
, "unsafe-coerce" , "unsafe-coerce"
] ]
"https://github.com/irresponsible/purescript-dom-simple" "https://github.com/irresponsible/purescript-dom-simple"
"v0.2.1" "v0.2.5"
, ffi-simple = , ffi-simple =
mkPackage mkPackage
[ "prelude" [ "prelude"
...@@ -163,7 +29,7 @@ let additions = ...@@ -163,7 +29,7 @@ let additions =
, "unsafe-coerce" , "unsafe-coerce"
] ]
"https://github.com/irresponsible/purescript-ffi-simple" "https://github.com/irresponsible/purescript-ffi-simple"
"v0.2.4" "v0.2.8"
, inflection = , inflection =
mkPackage mkPackage
[ "functions" ] [ "functions" ]
...@@ -173,7 +39,7 @@ let additions = ...@@ -173,7 +39,7 @@ let additions =
mkPackage mkPackage
[ "console", "foldable-traversable", "exceptions", "spec" ] [ "console", "foldable-traversable", "exceptions", "spec" ]
"https://github.com/purescript-spec/purescript-spec-mocha" "https://github.com/purescript-spec/purescript-spec-mocha"
"v3.0.0" "v4.0.0"
} }
in upstream // overrides // additions in upstream // additions
module Reactix module Reactix
( module Reactix.React ( module Exports
, module Reactix.Hooks
, module Reactix.SyntheticEvent
) where ) where
import Reactix.React import Reactix.React (class IsComponent, Component, Consumer, Context, Element, Hooks, Memo, Provider, React, ReactDOM, Ref, consume, consumeContext, consumer, createContext, createDOMElement, createElement, createPortal, createRef, fragment, hooksComponent, isValid, memo, memo', provide, provideContext, provider, react, reactDOM, readNullableRef, readRef, render, runHooks, setRef, staticComponent, unsafeHooksEffect) as Exports
import Reactix.Hooks import Reactix.Hooks (Reducer, State, nothing, thenNothing, unsafeUseCallback, unsafeUseEffect, unsafeUseImperativeHandle, unsafeUseLayoutEffect, unsafeUseMemo, useCallback, useCallback1, useCallback2, useCallback3, useCallback4, useCallback5, useContext, useDebugValue, useDebugValue', useEffect, useEffect', useEffect1, useEffect1', useEffect2, useEffect2', useEffect3, useEffect3', useEffect4, useEffect4', useEffect5, useEffect5', useEffectFn1, useEffectFn1', useEffectFn2, useEffectFn2', useEffectFn3, useEffectFn3', useEffectFn4, useEffectFn4', useEffectFn5, useEffectFn5', useEffectOnce, useEffectOnce', useImperativeHandle, useImperativeHandle1, useImperativeHandle2, useImperativeHandle3, useImperativeHandle4, useImperativeHandle5, useLayoutEffect, useLayoutEffect', useLayoutEffect1, useLayoutEffect1', useLayoutEffect2, useLayoutEffect2', useLayoutEffect3, useLayoutEffect3', useLayoutEffect4, useLayoutEffect4', useLayoutEffect5, useLayoutEffect5', useLayoutEffectFn1, useLayoutEffectFn1', useLayoutEffectFn2, useLayoutEffectFn2', useLayoutEffectFn3, useLayoutEffectFn3', useLayoutEffectFn4, useLayoutEffectFn4', useLayoutEffectFn5, useLayoutEffectFn5', useMemo, useMemo1, useMemo2, useMemo3, useMemo4, useMemo5, useReducer, useReducer', useRef, useState, useState') as Exports
import Reactix.SyntheticEvent (SyntheticEvent) import Reactix.SyntheticEvent (SyntheticEvent) as Exports
...@@ -42,6 +42,10 @@ import Reactix.React (Context, Hooks, Ref, react) ...@@ -42,6 +42,10 @@ import Reactix.React (Context, Hooks, Ref, react)
--- useState --- useState
-- delay concretely typed to Effect
delayEffect :: forall a b. a -> (a -> Effect b) -> Effect b
delayEffect = delay
-- | A state hook is a tuple of value and setter -- | A state hook is a tuple of value and setter
type State state = Tuple state ((state -> state) -> Effect Unit) type State state = Tuple state ((state -> state) -> Effect Unit)
...@@ -49,7 +53,7 @@ type State state = Tuple state ((state -> state) -> Effect Unit) ...@@ -49,7 +53,7 @@ type State state = Tuple state ((state -> state) -> Effect Unit)
useState :: forall s. (Unit -> s) -> Hooks (State s) useState :: forall s. (Unit -> s) -> Hooks (State s)
useState s = useState s =
hook $ \_ -> hook $ \_ ->
pure $ currySecond $ tuple $ react ... "useState" $ [ delay unit (pure <<< s) ] pure $ currySecond $ tuple $ react ... "useState" $ [ delayEffect unit (pure <<< s) ]
useState' :: forall s. s -> Hooks (State s) useState' :: forall s. s -> Hooks (State s)
useState' = useState <<< const useState' = useState <<< const
...@@ -317,7 +321,7 @@ useLayoutEffectFn5' a b c d e f = splay5 useLayoutEffect5' f a b c d e ...@@ -317,7 +321,7 @@ useLayoutEffectFn5' a b c d e f = splay5 useLayoutEffect5' f a b c d e
-- | Given a function to compute an expensive value, returns the value -- | Given a function to compute an expensive value, returns the value
useMemo :: forall t. (Unit -> t) -> Hooks t useMemo :: forall t. (Unit -> t) -> Hooks t
useMemo f = hook $ \_ -> pure $ react ... "useMemo" $ [ delay unit (\_ -> pure (f unit)) ] useMemo f = hook $ \_ -> pure $ react ... "useMemo" $ [ delayEffect unit (\_ -> pure (f unit)) ]
-- | Like `useMemo` but takes a memo value -- | Like `useMemo` but takes a memo value
useMemo1 :: forall a t. a -> (Unit -> t) -> Hooks t useMemo1 :: forall a t. a -> (Unit -> t) -> Hooks t
...@@ -346,13 +350,13 @@ unsafeUseMemo :: forall t a. (Unit -> t) -> a -> Hooks t ...@@ -346,13 +350,13 @@ unsafeUseMemo :: forall t a. (Unit -> t) -> a -> Hooks t
unsafeUseMemo f a = unsafeUseMemo f a =
hook $ \_ -> hook $ \_ ->
pure $ react ... "useMemo" $ pure $ react ... "useMemo" $
args2 (delay unit (\_ -> pure (f unit))) (Array.from a) args2 (delayEffect unit (\_ -> pure (f unit))) (Array.from a)
-- useCallback -- useCallback
-- | Given a function to compute an expensive value, returns the value -- | Given a function to compute an expensive value, returns the value
useCallback :: forall t. (Unit -> t) -> Hooks (Effect t) useCallback :: forall t. (Unit -> t) -> Hooks (Effect t)
useCallback f = hook $ \_ -> pure $ react ... "useCallback" $ [ delay unit (\_ -> pure (f unit)) ] useCallback f = hook $ \_ -> pure $ react ... "useCallback" $ [ delayEffect unit (\_ -> pure (f unit)) ]
-- | Like `useCallback` but takes a memo value -- | Like `useCallback` but takes a memo value
useCallback1 :: forall a t. a -> (Unit -> t) -> Hooks (Effect t) useCallback1 :: forall a t. a -> (Unit -> t) -> Hooks (Effect t)
......
...@@ -234,4 +234,3 @@ isValid a = react ... "isValidElement" $ [ a ] ...@@ -234,4 +234,3 @@ isValid a = react ... "isValidElement" $ [ a ]
children :: forall a. a -> Array Element children :: forall a. a -> Array Element
children a = react .. "Children" ... "toArray" $ [ (a .. "children") ] children a = react .. "Children" ... "toArray" $ [ (a .. "children") ]
...@@ -26,7 +26,7 @@ ucFirst = help <<< splitAt 1 ...@@ -26,7 +26,7 @@ ucFirst = help <<< splitAt 1
where help {before, after} = toUpper before <> after where help {before, after} = toUpper before <> after
-- I'm not quite sure of the type of this. Purescript "helpfully" says it's: -- I'm not quite sure of the type of this. Purescript "helpfully" says it's:
-- forall t202 t203 t205 t206. (t203 -> t205 -> t206) -> (t202 -> t203) -> ... -> ... onemore :: forall t24 t25 t27 t28. (t25 -> t27 -> t28) -> (t24 -> t25) -> (t24 -> t27) -> t24 -> t28
onemore s f g a = s (f a) (g a) onemore s f g a = s (f a) (g a)
-- Aka the `s` combinator from the SKI calculus -- Aka the `s` combinator from the SKI calculus
......
module Test.Main where module Test.Main where
import Prelude import Prelude
import Effect (Effect)
import Test.Spec (Spec, describe, it)
import Test.Spec.Assertions (shouldEqual)
import Test.Spec.Mocha (runMocha)
import Reactix.React.Spec
import Test.Spec.Runner (run)
import Effect (Effect)
import Effect.Aff (Aff)
import Reactix.React.Spec as ReactSpec import Reactix.React.Spec as ReactSpec
import Test.Spec (SpecT)
import Test.Spec.Mocha (runMocha)
specs :: Spec Unit specs :: SpecT Aff Unit Effect Unit
specs = do ReactSpec.spec specs = do ReactSpec.spec
main :: Effect Unit main :: Effect Unit
main = do -- >>= run [consoleReporter] main = do
-- specs <- discoverSpecs
runMocha specs runMocha specs
module Reactix.React.Spec where module Reactix.React.Spec where
import Prelude import Prelude
import DOM.Simple.Element as Element
import DOM.Simple.Types (Element)
import Data.Array ((!!))
import Data.Array as A import Data.Array as A
import Data.Array ( (!!) ) import Data.Maybe (Maybe(..))
import Data.Maybe ( Maybe(..) )
import Data.Traversable (sequence_, traverse_) import Data.Traversable (sequence_, traverse_)
import Data.Tuple.Nested ( (/\) ) import Data.Tuple.Nested ((/\))
import Data.Unfoldable (fromMaybe) import Data.Unfoldable (fromMaybe)
import Effect (Effect)
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Effect.Class ( liftEffect ) import Effect.Class (liftEffect)
import Effect.Ref as Ref import Effect.Ref as Ref
-- import Effect.Aff (launchAff_)
import Test.Spec ( Spec, describe, it )
import Test.Spec.Assertions ( shouldEqual )
-- import Test.Spec.QuickCheck (quickCheck')
import DOM.Simple.Element as Element
import DOM.Simple.Types (Element)
import FFI.Simple (delay) import FFI.Simple (delay)
import Reactix as R import Reactix as R
import Reactix.Test as RT
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Reactix.Test as RT
import Test.Spec (SpecT, describe, it)
import Test.Spec.Assertions (shouldEqual)
type Spec = SpecT Aff Unit Effect Unit
staticTest :: Spec Unit staticTest :: Spec
staticTest = staticTest =
describe "Basic DOM rendering" $ do describe "Basic DOM rendering" $ do
it "Simple elements" $ do it "Simple elements" $ do
...@@ -67,7 +69,7 @@ counterCpt = R.hooksComponent "Counter" cpt ...@@ -67,7 +69,7 @@ counterCpt = R.hooksComponent "Counter" cpt
[ H.button { type: "button", on: { click: \_ -> setY (_ + 1) } } [ H.text "++" ] [ H.button { type: "button", on: { click: \_ -> setY (_ + 1) } } [ H.text "++" ]
, H.div {} [ H.text (show y) ] ] , H.div {} [ H.text (show y) ] ]
counterTest :: Spec Unit counterTest :: Spec
counterTest = counterTest =
describe "Counter" do describe "Counter" do
it "Works for plain components" $ do it "Works for plain components" $ do
...@@ -111,7 +113,7 @@ bicounterCpt = R.hooksComponent "Bicounter" cpt ...@@ -111,7 +113,7 @@ bicounterCpt = R.hooksComponent "Bicounter" cpt
reduce count Inc = count + 1 reduce count Inc = count + 1
reduce count Dec = count - 1 reduce count Dec = count - 1
bicounterTest :: Spec Unit bicounterTest :: Spec
bicounterTest = bicounterTest =
describe "Bicounter" do describe "Bicounter" do
it "Works for plain components" $ do it "Works for plain components" $ do
...@@ -164,7 +166,7 @@ effectorCpt = R.hooksComponent "Effector" cpt ...@@ -164,7 +166,7 @@ effectorCpt = R.hooksComponent "Effector" cpt
pure $ H.div {} [] pure $ H.div {} []
-- TODO: test it's firing at the right time -- TODO: test it's firing at the right time
effectorTest :: Spec Unit effectorTest :: Spec
effectorTest = effectorTest =
describe "Effector" do describe "Effector" do
it "Works for plain components" $ it "Works for plain components" $
...@@ -192,7 +194,7 @@ layoutEffectorCpt = R.hooksComponent "LayoutEffector" cpt ...@@ -192,7 +194,7 @@ layoutEffectorCpt = R.hooksComponent "LayoutEffector" cpt
pure $ H.div {} [] pure $ H.div {} []
-- TODO: test it's firing at the right time -- TODO: test it's firing at the right time
layoutEffectorTest :: Spec Unit layoutEffectorTest :: Spec
layoutEffectorTest = layoutEffectorTest =
describe "LayoutEffector" do describe "LayoutEffector" do
it "Works for plain components" $ it "Works for plain components" $
...@@ -248,7 +250,7 @@ themeChooserCpt = R.hooksComponent "ThemeChooser" cpt ...@@ -248,7 +250,7 @@ themeChooserCpt = R.hooksComponent "ThemeChooser" cpt
[ H.text "Light" ] [ H.text "Light" ]
, R.provideContext context theme [ R.createElement themedCpt { theme: context } [] ] ] , R.provideContext context theme [ R.createElement themedCpt { theme: context } [] ] ]
themeChooserTest :: Spec Unit themeChooserTest :: Spec
themeChooserTest = themeChooserTest =
describe "ThemeChooser" do describe "ThemeChooser" do
it "Works for plain components" $ do it "Works for plain components" $ do
...@@ -295,7 +297,7 @@ themeChooserTest = ...@@ -295,7 +297,7 @@ themeChooserTest =
-- | count `mod` 5 == 0 = "Buzz" -- | count `mod` 5 == 0 = "Buzz"
-- | true = show count -- | true = show count
-- fizzBuzzTest :: Spec Unit -- fizzBuzzTest :: Spec
-- fizzBuzzTest = -- fizzBuzzTest =
-- describe "FizzBuzz" do -- describe "FizzBuzz" do
-- it "Works for plain components" $ -- it "Works for plain components" $
...@@ -310,15 +312,15 @@ themeChooserTest = ...@@ -310,15 +312,15 @@ themeChooserTest =
-- pure unit -- pure unit
-- memoTest :: Spec Unit -- memoTest :: Spec
-- callbackTest :: Spec Unit -- callbackTest :: Spec
-- imperativeHandleTest :: Spec Unit -- imperativeHandleTest :: Spec
-- debugValueTest :: Spec Unit -- debugValueTest :: Spec
-- listTest :: Spec Unit -- listTest :: Spec
-- listTest = pure unit -- listTest = pure unit
spec :: Spec Unit spec :: SpecT Aff Unit Effect Unit
spec = sequence_ spec = sequence_
[ staticTest [ staticTest
, counterTest -- useState , counterTest -- useState
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment