Skip to content

Events #140

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 1 commit into from
Apr 14, 2018
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
14 changes: 0 additions & 14 deletions src/React.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,3 @@ function createElementDynamic(class_) {
};
exports.createElementDynamicImpl = createElementDynamic;
exports.createElementTagNameDynamic = createElementDynamic;

function preventDefault(event) {
return function() {
event.preventDefault();
};
};
exports.preventDefault = preventDefault;

function stopPropagation(event) {
return function() {
event.stopPropagation();
};
};
exports.stopPropagation = stopPropagation;
59 changes: 14 additions & 45 deletions src/React.purs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ module React
, ReactThis
, TagName

, EventHandler

, Read
, Write
, Disallowed
Expand All @@ -30,18 +28,11 @@ module React
, ReactClass
, Ref

, Event
, MouseEvent
, KeyboardEvent

, EventHandlerContext

, component
, pureComponent
, statelessComponent

, getProps

, readState
, writeState
, writeStateWithCallback
Expand All @@ -50,16 +41,16 @@ module React
, forceUpdate
, forceUpdateCb

, handle
, preventDefault
, stopPropagation

, createElement
, createElementDynamic
, createElementTagName
, createElementTagNameDynamic
, createLeafElement

, SyntheticEventHandler
, SyntheticEventHandlerContext
, handle

, Children
, childrenToArray
, childrenCount
Expand All @@ -68,14 +59,20 @@ module React
, class IsReactElement
, toElement
, fragmentWithKey

, module SyntheticEvent
) where

import Prelude

import Control.Monad.Eff (kind Effect, Eff)
import Control.Monad.Eff.Exception (Error)
import Control.Monad.Eff.Uncurried (EffFn2, runEffFn2)

import Data.Nullable (Nullable)

import React.SyntheticEvent (preventDefault, isDefaultPrevented, stopPropagation, isPropagationStopped, persist) as SyntheticEvent

import Unsafe.Coerce (unsafeCoerce)

-- | Name of a tag.
Expand All @@ -91,7 +88,7 @@ foreign import data ReactComponent :: Type
foreign import data ReactThis :: Type -> Type -> Type

-- | An event handler. The type argument represents the type of the event.
foreign import data EventHandler :: Type -> Type
foreign import data SyntheticEventHandler :: Type -> Type

-- | This phantom type indicates that read access to a resource is allowed.
foreign import data Read :: Effect
Expand All @@ -116,32 +113,8 @@ foreign import data ReactState :: # Effect -> Effect
-- | This effect indicates that a computation may read the component props.
foreign import data ReactProps :: Effect

-- | The type of DOM events.
foreign import data Event :: Type

-- | The type of mouse events.
type MouseEvent =
{ pageX :: Number
, pageY :: Number
}

-- | The type of keyboard events.
type KeyboardEvent =
{ altKey :: Boolean
, ctrlKey :: Boolean
, charCode :: Int
, key :: String
, keyCode :: Int
, locale :: String
, location :: Int
, metaKey :: Boolean
, repeat :: Boolean
, shiftKey :: Boolean
, which :: Int
}

-- | A function which handles events.
type EventHandlerContext eff props state result =
type SyntheticEventHandlerContext eff props state result =
Eff
( props :: ReactProps
, state :: ReactState ReadWrite
Expand Down Expand Up @@ -355,13 +328,13 @@ forceUpdateCb this m = runEffFn2 forceUpdateCbImpl this m

-- | Create an event handler.
foreign import handle :: forall eff ev props state result.
(ev -> EventHandlerContext eff props state result) -> EventHandler ev
(ev -> SyntheticEventHandlerContext eff props state result) -> SyntheticEventHandler ev

class ReactPropFields (required :: # Type) (given :: # Type)

type ReservedReactPropFields r =
( key :: String
, ref :: EventHandler (Nullable Ref)
, ref :: SyntheticEventHandler (Nullable Ref)
| r
)

Expand Down Expand Up @@ -423,10 +396,6 @@ foreign import childrenToArray :: Children -> Array ReactElement
-- | Returns the number of children.
foreign import childrenCount :: Children -> Int

foreign import preventDefault :: forall eff. Event -> Eff eff Unit

foreign import stopPropagation :: forall eff. Event -> Eff eff Unit

class IsReactElement a where
toElement :: a -> ReactElement

Expand Down
Loading