Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rocketlaunchr/react
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.0.0
Choose a base ref
...
head repository: rocketlaunchr/react
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Aug 4, 2019

  1. - added fork of fmtless package (in order to make changes)

    - remove encoding/json package dependency
    rocketlaunchr-cto committed Aug 4, 2019
    Copy the full SHA
    c1bd92d View commit details

Commits on Aug 5, 2019

  1. - updated JSFn function

    - updated docs
    - added new JSONUnmarshal function for simple json unmarshaling
    rocketlaunchr-cto committed Aug 5, 2019
    Copy the full SHA
    888af85 View commit details
  2. - update docs

    rocketlaunchr-cto committed Aug 5, 2019
    Copy the full SHA
    ef2cc8d View commit details
  3. Copy the full SHA
    9eb7eeb View commit details

Commits on Aug 7, 2019

  1. Copy the full SHA
    5b9a634 View commit details

Commits on Sep 23, 2019

  1. Copy the full SHA
    0b7b6d5 View commit details
  2. Copy the full SHA
    bdb637e View commit details
  3. - update copyright

    rocketlaunchr-cto committed Sep 23, 2019
    Copy the full SHA
    d2dfe1f View commit details
  4. Copy the full SHA
    1d1a711 View commit details
  5. Copy the full SHA
    ec38e58 View commit details

Commits on Sep 24, 2019

  1. - update readme

    rocketlaunchr-cto committed Sep 24, 2019
    Copy the full SHA
    50eae21 View commit details
  2. Update readme

    rocketlaunchr-cto authored Sep 24, 2019
    Copy the full SHA
    f64804d View commit details

Commits on Sep 25, 2019

  1. Copy the full SHA
    5b4cdf5 View commit details
  2. - update docs

    rocketlaunchr-cto committed Sep 25, 2019
    Copy the full SHA
    5313602 View commit details
  3. - update docs

    rocketlaunchr-cto committed Sep 25, 2019
    Copy the full SHA
    1f4dfb2 View commit details
  4. Copy the full SHA
    757960e View commit details

Commits on Oct 11, 2019

  1. update readme

    rocketlaunchr-cto authored Oct 11, 2019
    Copy the full SHA
    e8c716b View commit details

Commits on Dec 16, 2019

  1. - update readme.

    rocketlaunchr-cto committed Dec 16, 2019
    Copy the full SHA
    7459f2f View commit details
  2. - update readme

    rocketlaunchr-cto committed Dec 16, 2019
    Copy the full SHA
    933b871 View commit details
  3. Copy the full SHA
    c527d11 View commit details

Commits on Dec 17, 2019

  1. Copy the full SHA
    6ce52de View commit details

Commits on Dec 18, 2019

  1. - update readme

    rocketlaunchr-cto authored Dec 18, 2019
    Copy the full SHA
    98dfa15 View commit details

Commits on Feb 9, 2020

  1. - add new logos

    rocketlaunchr-cto committed Feb 9, 2020
    Copy the full SHA
    b221237 View commit details
  2. - update copyright

    rocketlaunchr-cto committed Feb 9, 2020
    Copy the full SHA
    9a89d26 View commit details
  3. Copy the full SHA
    d6ad745 View commit details
  4. Copy the full SHA
    7074a6f View commit details
  5. - update readme

    rocketlaunchr-cto committed Feb 9, 2020
    Copy the full SHA
    2d8e29c View commit details
  6. - update readme

    rocketlaunchr-cto committed Feb 9, 2020
    Copy the full SHA
    5ce32e2 View commit details

Commits on Feb 10, 2020

  1. -update readme

    rocketlaunchr-cto committed Feb 10, 2020
    Copy the full SHA
    f0da4bb View commit details
  2. - update readme

    rocketlaunchr-cto committed Feb 10, 2020
    Copy the full SHA
    425a55c View commit details
86 changes: 60 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
Go with React [![GoDoc](http://godoc.org/github.com/rocketlaunchr/react?status.svg)](http://godoc.org/github.com/rocketlaunchr/react) [![Go Report Card](https://goreportcard.com/badge/github.com/rocketlaunchr/react)](https://goreportcard.com/report/github.com/rocketlaunchr/react)
===============
<p align="center">
<img src="https://github.com/rocketlaunchr/react/raw/master/logo.png" alt="react" />
</p>

# Go with React [![GoDoc](http://godoc.org/github.com/rocketlaunchr/react?status.svg)](http://godoc.org/github.com/rocketlaunchr/react) [![Go Report Card](https://goreportcard.com/badge/github.com/rocketlaunchr/react)](https://goreportcard.com/report/github.com/rocketlaunchr/react)

Facebook's React is one of the most dominant libraries for front-end development around. Google's Go programming language is one of the most elegantly crafted languages for server development. Why not combine the two?

This package is an extremely thin wrapper over the native react.js API. The objective was to make it light-weight, developer-friendly and intuitive. You shouldn’t have to scour the documentation to get going — a few peeks should be adequate. If you know your way around the React API and you know a bit of Go, then you should be able to make prototypes and production-worthy applications in no time.
This package is an extremely thin wrapper over the native react.js API. The objective was to make it light-weight, developer-friendly and intuitive. You shouldn’t have to scour the documentation to get going — a few peeks should be adequate. If you know your way around the React API and you know a bit of Go, then you should be able to make prototypes and production-worthy applications in no time.

This package is best suited for making cross-platform Desktop applications using these technologies:

- [webview](https://github.com/zserge/webview)
- [lorca](https://github.com/zserge/lorca)
- [go-astilectron](https://github.com/asticode/go-astilectron)
- [gotron](https://github.com/Equanox/gotron)
- **[electron.js](https://electronjs.org/)**

The package is **production ready**. An optional (but highly convenient) `elements` sub-package is also included.

See [Tutorial here](https://medium.com/@rocketlaunchr.cloud/go-with-react-de5ee4f01df9).

**the project to show your appreciation.**

## Dependencies

* [React 16.5.2](https://www.npmjs.com/package/react) (it will probably work with lower)
* [Gopherjs](https://github.com/gopherjs/gopherjs)
* [create-react-class](https://www.npmjs.com/package/create-react-class)
- [React 16.5.2](https://www.npmjs.com/package/react) (it will probably work with lower)
- [Gopherjs](https://github.com/gopherjs/gopherjs) (Go to Javascript transpiler)
- [create-react-class](https://www.npmjs.com/package/create-react-class)
- [react-addons-pure-render-mixin](https://www.npmjs.com/package/react-addons-pure-render-mixin) (optional: For creating a `PureComponent`)

## Installation

@@ -24,45 +38,65 @@ go get -u github.com/rocketlaunchr/react
## Examples

The examples can be [found here](https://github.com/rocketlaunchr/react/tree/master/examples):

### Uptime Timer

* How to create React class components
* How to pass props from parent to child
* How to use **UnmarshalProps()** and **UnmarshalState()**
* How to use **state()** and **setState()**
* How to create strongly-typed structured props and states
- How to create React class components
- How to pass props from parent to child
- How to use **UnmarshalProps()** and **UnmarshalState()**
- How to use **state()** and **setState()**
- How to create strongly-typed structured props and states

### Event Handling

* How to create React functional components
* How to handle events (and pass extra arguments)
* How to create a Ref and interact with dom object directly
- How to create React functional components
- How to handle events (and pass extra arguments)
- How to create a Ref and interact with dom object directly

### [Desktop Application](https://github.com/rocketlaunchr/desktop-application)

- 100% written in Go
- Cross-platform (macOS, Win, Linux)
- [Electron.js](https://electronjs.org/) based
- How to bundle javascript dependencies using [rollup.js](https://rollupjs.org)

## Performance Tips

* Use `-m` command line flag to instruct gopher.js to minify code. Then bundle+minify further with [Rollup.js](https://rollupjs.org) xor [Webpack/UglifyJS](https://github.com/gopherjs/gopherjs/issues/136). A Webpack tutorial can be [found here](https://medium.com/ag-grid/webpack-tutorial-understanding-how-it-works-f73dfa164f01).
* Apply [gzip compression](https://en.wikipedia.org/wiki/HTTP_compression)
* Use int instead of (u)int8/16/32/64
* Use float64 instead of float32
* Avoid importing `fmt` at all costs (including indirectly).
* Use **react.JSFn()** and use native javascript functions as much as possible.
* https://github.com/gopherjs/gopherjs/wiki/JavaScript-Tips-and-Gotchas
* See if [jsgo](https://github.com/dave/jsgo) is appropriate for your web-based project.
- Use `-m` command line flag to instruct gopher.js to minify code. Then bundle+minify further with [rollup.js](https://rollupjs.org) xor [Webpack/UglifyJS](https://github.com/gopherjs/gopherjs/issues/136). A Webpack tutorial can be [found here](https://medium.com/ag-grid/webpack-tutorial-understanding-how-it-works-f73dfa164f01).
- Apply [gzip compression](https://en.wikipedia.org/wiki/HTTP_compression)
- Use int instead of (u)int8/16/32/64
- Use float64 instead of float32
- Avoid importing `fmt` at all costs (including indirectly). Use [fmtless](https://github.com/rocketlaunchr/react/forks/fmtless) instead.
- Avoid importing `net/http` for http requests (including indirectly). Use [gopherjs-xhr](https://github.com/rocketlaunchr/gopherjs-xhr) instead.
- Until GopherJS supports Go1.13+, avoid using the standard libraries `context` package because it uses `fmt`. Instead use [`context`](https://github.com/rocketlaunchr/react/forks/context) from `forks` sub-package.
- Avoid importing `honnef.co/go/js/dom` if possible.
- Use **react.JSFn()** and use native javascript functions as much as possible.
- https://github.com/gopherjs/gopherjs/wiki/JavaScript-Tips-and-Gotchas
- See if [jsgo](https://github.com/dave/jsgo) is appropriate for your web-based project.
- To reduce file size, copy only what's required from `elements` sub-package.
- For json unmarshaling, try [slim-decoder](https://github.com/gopherjs/gopherjs/wiki/Using-native-JSON-parsing-to-realize-a-slim-JSON-decoder) or use [json](https://github.com/rocketlaunchr/react/forks/encoding/json)

## Future Work

* WebAssembly version
- WebAssembly version ![Help Required](https://img.shields.io/badge/help-required-blueviolet)

## Other useful packages

- [dataframe-go](https://github.com/rocketlaunchr/dataframe-go) - Statistics and data manipulation
- [dbq](https://github.com/rocketlaunchr/dbq) - Zero boilerplate database operations for Go
- [electron-alert](https://github.com/rocketlaunchr/electron-alert) - SweetAlert2 for Electron Applications
- [igo](https://github.com/rocketlaunchr/igo) - A Go transpiler with cool new syntax such as fordefer (defer for for-loops)
- [mysql-go](https://github.com/rocketlaunchr/mysql-go) - Properly cancel slow MySQL queries
- [remember-go](https://github.com/rocketlaunchr/remember-go) - Cache slow database queries

#

### Legal Information

The license is a modified MIT license. Refer to `LICENSE` file for more details.

**© 2018 PJ Engineering and Business Solutions Pty. Ltd.**
**© 2018-20 PJ Engineering and Business Solutions Pty. Ltd.**

### Final Notes

Feel free to enhance features by issuing pull-requests.

**Star** the project to show your appreciation.
8 changes: 2 additions & 6 deletions elements/elements.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright 2018-20 PJ Engineering and Business Solutions Pty. Ltd. All rights reserved.

package elements

import (
@@ -13,12 +15,6 @@ var (
FALSE = false
)

//
// PULL-REQUESTS WILL BE WARMLY WELCOMED
// Some of the field types are likely to change
// to more appropriate types.
//

// AProps ...
type AProps struct {
AriaSet react.Set `react:"aria-,omitempty"`
2 changes: 2 additions & 0 deletions elements/styles.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright 2018-20 PJ Engineering and Business Solutions Pty. Ltd. All rights reserved.

package elements

// Styles represent CSS3 attributes.
10 changes: 10 additions & 0 deletions forks/context/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package context

import "time"

type Context interface {
Deadline() (deadline time.Time, ok bool)
Done() <-chan struct{}
Err() error
Value(key interface{}) interface{}
}
36 changes: 36 additions & 0 deletions forks/context/context_go113.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// +build go1.13

package context

import (
"context"
"time"
)

var Canceled = context.Canceled

var DeadlineExceeded error = context.DeadlineExceeded

func WithCancel(parent context.Context) (ctx context.Context, cancel context.CancelFunc) {
return context.WithCancel(parent)
}

func WithDeadline(parent context.Context, d time.Time) (context.Context, context.CancelFunc) {
return context.WithDeadline(parent, d)
}

func WithTimeout(parent context.Context, timeout time.Duration) (context.Context, context.CancelFunc) {
return context.WithTimeout(parent, timeout)
}

func Background() context.Context {
return context.Background()
}

func TODO() context.Context {
return context.TODO()
}

func WithValue(parent context.Context, key, val interface{}) context.Context {
return context.WithValue(parent, key, val)
}
179 changes: 179 additions & 0 deletions forks/context/context_legacy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
// Copyright 2016 Google Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to writing, software distributed
// under the License is distributed on a "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.

// +build !go1.13

// See https://golang.org/pkg/context/ for documentation

package context

import (
"errors"
"reflect"
"sync"
"time"
)

var Canceled = errors.New("context canceled")

var DeadlineExceeded = deadlineExceededError{}

type deadlineExceededError struct{}

func (deadlineExceededError) Error() string { return "context deadline exceeded" }
func (deadlineExceededError) Timeout() bool { return true }
func (deadlineExceededError) Temporary() bool { return true }

type emptyCtx int

func (*emptyCtx) Deadline() (deadline time.Time, ok bool) {
return
}
func (*emptyCtx) Done() <-chan struct{} {
return nil
}
func (*emptyCtx) Err() error {
return nil
}
func (*emptyCtx) Value(key interface{}) interface{} {
return nil
}

func (e *emptyCtx) String() string {
switch e {
case background:
return "context.Background"
case todo:
return "context.TODO"
}
return "unknown empty Context"
}

var (
background = new(emptyCtx)
todo = new(emptyCtx)
)

func Background() Context {
return background
}

func TODO() Context {
return todo
}

type CancelFunc func()

func WithCancel(parent Context) (Context, CancelFunc) {
ctx := &cancelCtx{
Context: parent,
done: make(chan struct{}),
}

cancel := func() { ctx.cancel(Canceled) }

go func() {
select {
case <-parent.Done():
ctx.cancel(parent.Err())
case <-ctx.Done():
}
}()

return ctx, cancel
}

type cancelCtx struct {
Context
done chan struct{}
err error
mu sync.Mutex
}

func (ctx *cancelCtx) Done() <-chan struct{} { return ctx.done }

func (ctx *cancelCtx) Err() error {
ctx.mu.Lock()
defer ctx.mu.Unlock()
return ctx.err
}

func (ctx *cancelCtx) cancel(err error) {
ctx.mu.Lock()
defer ctx.mu.Unlock()
if ctx.err != nil {
return
}
ctx.err = err
close(ctx.done)
}

func WithDeadline(parent Context, deadline time.Time) (Context, CancelFunc) {
cctx, cancel := WithCancel(parent)

ctx := &deadlineCtx{
cancelCtx: cctx.(*cancelCtx),
deadline: deadline,
}

timeout := time.Until(deadline)
t := time.AfterFunc(timeout, func() {
ctx.cancel(DeadlineExceeded)
})

stop := func() {
t.Stop()
cancel()
}

return ctx, stop
}

type deadlineCtx struct {
*cancelCtx
deadline time.Time
}

func (ctx *deadlineCtx) Deadline() (deadline time.Time, ok bool) {
return ctx.deadline, true
}

func WithTimeout(parent Context, timeout time.Duration) (Context, CancelFunc) {
return WithDeadline(parent, time.Now().Add(timeout))
}

func WithValue(parent Context, key, value interface{}) Context {
if key == nil {
panic("key is nil")
}
if !reflect.TypeOf(key).Comparable() {
panic("key is not comparable")
}
return &valueCtx{
Context: parent,
key: key,
value: value,
}
}

type valueCtx struct {
Context
value, key interface{}
}

func (ctx *valueCtx) Value(key interface{}) interface{} {
if key == ctx.key {
return ctx.value
}
return ctx.Context.Value(key)
}
Loading