Skip to content

Commit

Permalink
Make attributes more open to extension
Browse files Browse the repository at this point in the history
  • Loading branch information
shogowada committed Apr 30, 2017
1 parent 3bdf52b commit 05fd24f
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 54 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ ReactDOM.render(<.div(^.id := "hello-world")("Hello, World!"), mountNode)
2. Depend on the libraries.
```
libraryDependencies ++= Seq(
"io.github.shogowada" %%% "scalajs-reactjs" % "0.13.0", // For react facade
"io.github.shogowada" %%% "scalajs-reactjs-router-dom" % "0.13.0", // Optional. For react-router-dom facade
"io.github.shogowada" %%% "scalajs-reactjs-router-redux" % "0.13.0", // Optional. For react-router-redux facade
"io.github.shogowada" %%% "scalajs-reactjs-redux" % "0.13.0", // Optional. For react-redux facade
"io.github.shogowada" %%% "scalajs-reactjs-redux-devtools" % "0.13.0" // Optional. For redux-devtools facade
"io.github.shogowada" %%% "scalajs-reactjs" % "0.13.1", // For react facade
"io.github.shogowada" %%% "scalajs-reactjs-router-dom" % "0.13.1", // Optional. For react-router-dom facade
"io.github.shogowada" %%% "scalajs-reactjs-router-redux" % "0.13.1", // Optional. For react-router-redux facade
"io.github.shogowada" %%% "scalajs-reactjs-redux" % "0.13.1", // Optional. For react-redux facade
"io.github.shogowada" %%% "scalajs-reactjs-redux-devtools" % "0.13.1" // Optional. For redux-devtools facade
)
```

Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ publishArtifact := false
val commonSettings = Seq(
organization := "io.github.shogowada",
name := "scalajs-reactjs",
version := "0.13.0",
version := "0.13.1",
licenses := Seq("MIT" -> url("https://opensource.org/licenses/MIT")),
homepage := Some(url("https://github.com/shogowada/scalajs-reactjs")),
scalaVersion := "2.12.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import scala.scalajs.js.JSConverters._

object VirtualDOM extends VirtualDOM

trait EventVirtualDOMAttributes {

object EventVirtualDOMAttributes {
trait OnEventAttribute[Event <: SyntheticEvent] extends AttributeSpec {
val name: String

Expand All @@ -30,58 +29,63 @@ trait EventVirtualDOMAttributes {
}
}

// Animation Events
case class OnAnimationEventAttribute(name: String) extends OnEventAttribute[AnimationSyntheticEvent]
case class OnClipboardEventAttribute(name: String) extends OnEventAttribute[ClipboardSyntheticEvent]
case class OnCompositionEventAttribute(name: String) extends OnEventAttribute[CompositionSyntheticEvent]
case class OnFocusEventAttribute(name: String) extends OnEventAttribute[FocusSyntheticEvent]
case class OnFormEventAttribute[FormEvent <: FormSyntheticEvent[_]](name: String) extends OnEventAttribute[FormEvent]
case class OnImageEventAttribute(name: String) extends OnEventAttribute[ImageSyntheticEvent]
case class OnKeyboardEventAttribute(name: String) extends OnEventAttribute[KeyboardSyntheticEvent]
case class OnMediaEventAttribute(name: String) extends OnEventAttribute[MediaSyntheticEvent]
case class OnMouseEventAttribute(name: String) extends OnEventAttribute[MouseSyntheticEvent]
case class OnSelectionEventAttribute(name: String) extends OnEventAttribute[SelectionSyntheticEvent]
case class OnTouchEventAttribute(name: String) extends OnEventAttribute[TouchSyntheticEvent]
case class OnTransitionEventAttribute(name: String) extends OnEventAttribute[TransitionSyntheticEvent]
case class OnUIEventAttribute(name: String) extends OnEventAttribute[UISyntheticEvent]
case class OnWheelEventAttribute(name: String) extends OnEventAttribute[WheelSyntheticEvent]
case class OnErrorEventAttribute(name: String) extends OnEventAttribute[SyntheticEvent]
}

trait EventVirtualDOMAttributes {

import EventVirtualDOMAttributes._

// Animation Events
lazy val onAnimationStart = OnAnimationEventAttribute("onAnimationStart")
lazy val onAnimationEnd = OnAnimationEventAttribute("onAnimationEnd")
lazy val onAnimationIteration = OnAnimationEventAttribute("onAnimationIteration")

// Clipboard Events
case class OnClipboardEventAttribute(name: String) extends OnEventAttribute[ClipboardSyntheticEvent]

lazy val onCopy = OnClipboardEventAttribute("onCopy")
lazy val onCut = OnClipboardEventAttribute("onCut")
lazy val onPaste = OnClipboardEventAttribute("onPaste")

// Composition Events
case class OnCompositionEventAttribute(name: String) extends OnEventAttribute[CompositionSyntheticEvent]

lazy val onCompositionEnd = OnCompositionEventAttribute("onCompositionEnd")
lazy val onCompositionStart = OnCompositionEventAttribute("onCompositionStart")
lazy val onCompositionUpdate = OnCompositionEventAttribute("onCompositionUpdate")

// Focus Events
case class OnFocusEventAttribute(name: String) extends OnEventAttribute[FocusSyntheticEvent]

lazy val onFocus = OnFocusEventAttribute("onFocus")
lazy val onBlur = OnFocusEventAttribute("onBlur")

// Form Events
case class OnFormEventAttribute[FormEvent <: FormSyntheticEvent[_]](name: String) extends OnEventAttribute[FormEvent]

lazy val onChange = OnFormEventAttribute("onChange")
lazy val onInput = OnFormEventAttribute("onInput")
lazy val onSubmit = OnFormEventAttribute("onSubmit")

// Image Events
case class OnImageEventAttribute(name: String) extends OnEventAttribute[ImageSyntheticEvent]

lazy val onLoad = OnImageEventAttribute("onLoad")

// onError conflicts with Media Events. Conflicts are treated specially at the bottom of this trait.
// lazy val onError = OnImageEventAttribute("onError")

// Keyboard Events
case class OnKeyboardEventAttribute(name: String) extends OnEventAttribute[KeyboardSyntheticEvent]

lazy val onKeyDown = OnKeyboardEventAttribute("onKeyDown")
lazy val onKeyPress = OnKeyboardEventAttribute("onKeyPress")
lazy val onKeyUp = OnKeyboardEventAttribute("onKeyUp")

// Media Events
case class OnMediaEventAttribute(name: String) extends OnEventAttribute[MediaSyntheticEvent]

lazy val onAbort = OnMediaEventAttribute("onAbort")
lazy val onCanPlay = OnMediaEventAttribute("onCanPlay")
lazy val onCanPlayThrough = OnMediaEventAttribute("onCanPlayThrough")
Expand All @@ -108,8 +112,6 @@ trait EventVirtualDOMAttributes {
lazy val onWaiting = OnMediaEventAttribute("onWaiting")

// Mouse Events
case class OnMouseEventAttribute(name: String) extends OnEventAttribute[MouseSyntheticEvent]

lazy val onClick = OnMouseEventAttribute("onClick")
lazy val onContextMenu = OnMouseEventAttribute("onContextMenu")
lazy val onDoubleClick = OnMouseEventAttribute("onDoubleClick")
Expand All @@ -130,44 +132,31 @@ trait EventVirtualDOMAttributes {
lazy val onMouseUp = OnMouseEventAttribute("onMouseUp")

// Selection Events
case class OnSelectionEventAttribute(name: String) extends OnEventAttribute[SelectionSyntheticEvent]

lazy val onSelect = OnSelectionEventAttribute("onSelect")

// Touch Events
case class OnTouchEventAttribute(name: String) extends OnEventAttribute[TouchSyntheticEvent]

lazy val onTouchCancel = OnTouchEventAttribute("onTouchCancel")
lazy val onTouchEnd = OnTouchEventAttribute("onTouchEnd")
lazy val onTouchMove = OnTouchEventAttribute("onTouchMove")
lazy val onTouchStart = OnTouchEventAttribute("onTouchStart")

// Transition Events
case class OnTransitionEventAttribute(name: String) extends OnEventAttribute[TransitionSyntheticEvent]

lazy val onTransitionEnd = OnTransitionEventAttribute("onTransitionEnd")

// UI Events
case class OnUIEventAttribute(name: String) extends OnEventAttribute[UISyntheticEvent]

lazy val onScroll = OnUIEventAttribute("onScroll")

// Wheel Events
case class OnWheelEventAttribute(name: String) extends OnEventAttribute[WheelSyntheticEvent]

lazy val onWheel = OnWheelEventAttribute("onWheel")

// Events that conflicted with other events
case class OnErrorEventAttribute(name: String) extends OnEventAttribute[SyntheticEvent]

lazy val onError = OnErrorEventAttribute("onError")
}

trait VirtualDOM extends StaticTags {

class VirtualDOMElements extends Elements {
def apply(reactClass: ReactClass): ReactClassElementSpec =
ReactClassElementSpec(reactClass)
def apply(reactClass: ReactClass): ReactClassElementSpec = ReactClassElementSpec(reactClass)
}

object VirtualDOMElements {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package io.github.shogowada.scalajs.reactjs.redux
import io.github.shogowada.scalajs.reactjs.React
import io.github.shogowada.scalajs.reactjs.React.Props
import io.github.shogowada.scalajs.reactjs.VirtualDOM.VirtualDOMAttributes.Type.AS_IS
import io.github.shogowada.scalajs.reactjs.VirtualDOM.VirtualDOMElements.ReactClassElementSpec
import io.github.shogowada.scalajs.reactjs.VirtualDOM.{VirtualDOMAttributes, VirtualDOMElements}
import io.github.shogowada.scalajs.reactjs.classes.ReactClass
import io.github.shogowada.scalajs.reactjs.redux.ReactRedux.ReactReduxVirtualDOMAttributes.StoreAttributeSpec
Expand All @@ -18,7 +17,7 @@ object ReactRedux {
import Redux.Dispatch

implicit class ReactReduxVirtualDOMElements(elements: VirtualDOMElements) {
lazy val Provider = ReactClassElementSpec(NativeReactReduxProvider)
lazy val Provider = elements(NativeReactReduxProvider)
}

object ReactReduxVirtualDOMAttributes {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.shogowada.scalajs.reactjs.router.dom

import io.github.shogowada.scalajs.reactjs.VirtualDOM.VirtualDOMAttributes.Type.AS_IS
import io.github.shogowada.scalajs.reactjs.VirtualDOM.VirtualDOMElements.ReactClassElementSpec
import io.github.shogowada.scalajs.reactjs.VirtualDOM.{VirtualDOMAttributes, VirtualDOMElements}
import io.github.shogowada.scalajs.reactjs.classes.ReactClass
import io.github.shogowada.scalajs.reactjs.router
Expand Down Expand Up @@ -29,10 +28,10 @@ object NativeNavLink extends ReactClass

trait RouterDOM extends router.Router {
implicit class RouterDOMVirtualDOMElements(elements: VirtualDOMElements) {
lazy val BrowserRouter = ReactClassElementSpec(NativeBrowserRouter)
lazy val HashRouter = ReactClassElementSpec(NativeHashRouter)
lazy val Link = ReactClassElementSpec(NativeLink)
lazy val NavLink = ReactClassElementSpec(NativeNavLink)
lazy val BrowserRouter = elements(NativeBrowserRouter)
lazy val HashRouter = elements(NativeHashRouter)
lazy val Link = elements(NativeLink)
lazy val NavLink = elements(NativeNavLink)
}

object RouterDOMVirtualDOMAttributes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package io.github.shogowada.scalajs.reactjs.router.redux

import io.github.shogowada.scalajs.history.History
import io.github.shogowada.scalajs.reactjs.VirtualDOM.VirtualDOMElements
import io.github.shogowada.scalajs.reactjs.VirtualDOM.VirtualDOMElements.ReactClassElementSpec
import io.github.shogowada.scalajs.reactjs.classes.ReactClass
import io.github.shogowada.scalajs.reactjs.redux.Redux.{Middleware, NativeMiddleware, Reducer}
import io.github.shogowada.scalajs.reactjs.redux.{NativeAction, ReduxInternal}
Expand All @@ -27,7 +26,7 @@ object ReactRouterReduxAction extends js.Object {

object ReactRouterRedux {
implicit class RouterReduxVirtualDOMElements(elements: VirtualDOMElements) {
lazy val ConnectedRouter = ReactClassElementSpec(NativeReactRouterRedux.ConnectedRouter)
lazy val ConnectedRouter = elements(NativeReactRouterRedux.ConnectedRouter)
}

val routerReducer: Reducer[js.Object] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package io.github.shogowada.scalajs.reactjs.router
import io.github.shogowada.scalajs.history.History
import io.github.shogowada.scalajs.reactjs.VirtualDOM.VirtualDOMAttributes.Type.AS_IS
import io.github.shogowada.scalajs.reactjs.VirtualDOM.VirtualDOMAttributes.{ReactClassAttributeSpec, RenderAttributeSpec}
import io.github.shogowada.scalajs.reactjs.VirtualDOM.VirtualDOMElements.ReactClassElementSpec
import io.github.shogowada.scalajs.reactjs.VirtualDOM.{VirtualDOMAttributes, VirtualDOMElements}
import io.github.shogowada.scalajs.reactjs.classes.ReactClass
import io.github.shogowada.statictags.{Attribute, AttributeSpec, BooleanAttributeSpec, StringAttributeSpec}
Expand Down Expand Up @@ -33,11 +32,11 @@ object NativeSwitch extends ReactClass

trait Router {
implicit class RouterVirtualDOMElements(elements: VirtualDOMElements) {
lazy val Prompt = ReactClassElementSpec(NativePrompt)
lazy val Redirect = ReactClassElementSpec(NativeRedirect)
lazy val Route = ReactClassElementSpec(NativeRoute)
lazy val Router = ReactClassElementSpec(NativeRouter)
lazy val Switch = ReactClassElementSpec(NativeSwitch)
lazy val Prompt = elements(NativePrompt)
lazy val Redirect = elements(NativeRedirect)
lazy val Route = elements(NativeRoute)
lazy val Router = elements(NativeRouter)
lazy val Switch = elements(NativeSwitch)
}

object RouterVirtualDOMAttributes {
Expand Down

0 comments on commit 05fd24f

Please sign in to comment.