Giter Site home page Giter Site logo

scalajs-reactjs's Introduction

scalajs-reactjs

โš ๏ธ This project is not maintained anymore, and I'm looking for a kind person who can take it over from me. If you can inherit this project, please send a pull request to this README.md linking to your project so that we can direct people to the new home.

Further maintenance of the repo can be found here:

Build Status

Develop React applications with Scala. It is compatible with Scala 2.12 and Scala.js 0.6.14.

Optionally include react-router and react-redux facades, too.

Quick Look

import io.github.shogowada.scalajs.reactjs.VirtualDOM._
import io.github.shogowada.scalajs.reactjs.{React, ReactDOM}
import org.scalajs.dom

case class WrappedProps(name: String)

val reactClass = React.createClass[WrappedProps, Unit](
  (self) => <.div(^.id := "hello-world")(s"Hello, ${self.props.wrapped.name}!")
)

val mountNode = dom.document.getElementById("mount-node")
ReactDOM.render(<(reactClass)(^.wrapped := WrappedProps("World"))(), mountNode)

You can also directly render without creating a React class:

import io.github.shogowada.scalajs.reactjs.ReactDOM
import io.github.shogowada.scalajs.reactjs.VirtualDOM._
import org.scalajs.dom

val mountNode = dom.document.getElementById("mount-node")
ReactDOM.render(<.div(^.id := "hello-world")("Hello, World!"), mountNode)

How to Use

  1. Apply scalajs-bundler plugin.
  2. Depend on the libraries.
    libraryDependencies ++= Seq(
      "io.github.shogowada" %%% "scalajs-reactjs" % "0.14.0", // For react facade
      "io.github.shogowada" %%% "scalajs-reactjs-router-dom" % "0.14.0", // Optional. For react-router-dom facade
      "io.github.shogowada" %%% "scalajs-reactjs-router-redux" % "0.14.0", // Optional. For react-router-redux facade
      "io.github.shogowada" %%% "scalajs-reactjs-redux" % "0.14.0", // Optional. For react-redux facade
      "io.github.shogowada" %%% "scalajs-reactjs-redux-devtools" % "0.14.0" // Optional. For redux-devtools facade
    )
    

Examples

Reusable Components

scalajs-reactjs's People

Contributors

shogowada avatar viktor-podzigun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

scalajs-reactjs's Issues

Create ReactClassBuilder

Many developers are more comfortable writing functions than classes. Create ReactClassBuilder that lets you create ReactClass purely by composing functions.

Draft (incomplete and highly likely to change, but just to demonstrate the idea):

case class ReactClassContext[WrappedProps, State](
  native: js.Dynamic,
  props: Props[WrappedProps],
  state: State
) {
  def setState(state: State): Unit = // ...
}

val reactClass: ReactClass =
    ReactClassBuilder[Props, State]()
        .shouldComponentUpdate((context: ReactClassContext[WrappedProps, State], nextContext: ReactClassContext[WrappedProps, State]) => Boolean)
        .render((context: ReactClassContext[WrappedProps, State]) => ReactElement)
        .build

Fix signature of Provider for react-redux facade

The provider must take only one ReactElement, but the signature is taking multiple. Change the signature so that it only takes one ReactElement.

Current signature:

def Provider(store: Store)(children: js.Any*): ReactElement

Desired signature:

def Provider(store: Store)(child: ReactElement): ReactElement

Optimize shouldComponentUpdate

Right now, it's always returning true. Optimize the method so that it does the equivalent of the native React: shallow comparison of old props and new props and old state and new state.

Create Reducer[State] trait

Many find it easier to test with dependency injection. One of the ways to achieve dependency injection is to inject dependencies to class's constructor.

Create the following trait:

trait Reducer[State] {
  def apply(maybeState: Option[State], action: Action): State
}

And add the following method to Redux facade:

def createStore[State](reducer: Reducer[State]): Store

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.