reduxa

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2017 License: MIT Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

reduxa

goa plug-in to generate redux boilerplate

Project status: Reduxa is still experimental however the generated code has been used in production. Pull requests are welcome.

Breaking changes: Release 0.2.x substantially updates the templates. Use 0.1.0 if you are dependent on the initial release.

Reduxa assumes you are using ES6 and likely Babel.

I recommend formatting the Reduxa output with Prettier

Reduxa output will conform closley to Prettier Prettier and Airbnb Javascript Style Guide, with the biggest exception being line length. Future versions of Reduxa might optionally invoke Prettier from the generator.

Reduxa currently generates your action types, actions, and action creators for use with Redux, Axios, and Redux Thunk middleware. Scaffolding for reducers is under consideration for the future roadmap.

Thanks to Dan Abramov for Redux and to Raphael Simon for Goa.

Examples, based on goa's goa-cellar design:

Full example output is in the examples folder.

goagen gen -d github.com/goadesign/goa-cellar/design --pkg-path=github.com/kkeuning/reduxa

Generated Redux action types:

export const REQ_LIST_BOTTLES = 'REQ_LIST_BOTTLES';
export const RCV_LIST_BOTTLES_SUCCESS = 'RCV_LIST_BOTTLES_SUCCESS';
export const RCV_LIST_BOTTLES_ERROR = 'RCV_LIST_BOTTLES_ERROR';

Generated Redux actions:

export const requestListBottles = () => ({
  type: types.REQ_LIST_BOTTLES
});
export const receiveListBottlesSuccess = (data, status) => ({
  type: types.RCV_LIST_BOTTLES_SUCCESS,
  data,
  status
});
export const receiveListBottlesError = (data, status) => ({
  type: types.RCV_LIST_BOTTLES_ERROR,
  data,
  status
});

Generated Redux action creator for use with Thunk middleware:

// listBottles calls the list action of the bottle resource.
// url is the request url, the format is:
// http://localhost:8081/cellar/accounts/:accountID/bottles
// Optional handleError and handleSuccess functions can be provided for the promise
// if needed in addition to the redux actions.
// Standard or custom headers can be passed in like this in the options:
// { headers: {'X-My-Custom-Header': 'Header-Value'} }
// The options object will take precedence over default values for timeout, etc.
// This function returns a promise which dispatches an error if the HTTP response is a 4xx or 5xx.
//
// Query Parameters: years is expected in params.
// Params should be passed in the options object.
export const listBottles = (url, options, handleSuccess, handleError) =>
  dispatch => {
    dispatch(actions.requestListBottles());
    return axios({
      timeout: 20000,
      url,
      method: 'get',
      responseType: 'json',
      ...options
    })
      .then(response => {
        dispatch(actions.receiveListBottlesSuccess(response.data, response.status));
      })
      .then(response => {
        if (handleSuccess) {
          handleSuccess(response);
        }
      })
      .catch(error => {
        let rdata;
        if (error.response) {
          rdata = error.response.data;
        }
        dispatch(actions.receiveListBottlesError(rdata, error.status));
        throw error;
      })
      .catch(error => {
        if (handleError) {
          handleError(error);
        }
      });
  };

Documentation

Index

Constants

This section is empty.

Variables

View Source
var JavaScriptReserved = map[string]bool{

	"break":    true,
	"case":     true,
	"comment":  true,
	"continue": true,
	"default":  true,
	"delete":   true,
	"do":       true,
	"else":     true,
	"export":   true,
	"for":      true,
	"function": true,
	"if":       true,
	"import":   true,
	"in":       true,
	"label":    true,
	"new":      true,
	"return":   true,
	"switch":   true,
	"this":     true,
	"var":      true,
	"void":     true,
	"while":    true,
	"with":     true,

	"catch":    true,
	"class":    true,
	"const":    true,
	"debugger": true,
	"enum":     true,
	"extends":  true,
	"finally":  true,
	"super":    true,
	"throw":    true,
	"try":      true,

	"alert":       true,
	"confirm":     true,
	"open":        true,
	"print":       true,
	"NaN":         true,
	"Date":        true,
	"constructor": true,
	"assign":      true,
	"location":    true,
	"Location":    true,
	"window":      true,
	"Window":      true,

	"abstract":     true,
	"boolean":      true,
	"byte":         true,
	"char":         true,
	"double":       true,
	"false":        true,
	"final":        true,
	"float":        true,
	"goto":         true,
	"implements":   true,
	"instanceof":   true,
	"int":          true,
	"interface":    true,
	"long":         true,
	"native":       true,
	"null":         true,
	"package":      true,
	"private":      true,
	"protected":    true,
	"public":       true,
	"short":        true,
	"static":       true,
	"synchronized": true,
	"throws":       true,
	"transient":    true,
	"true":         true,
}

Reserved JavaScript keywords

Functions

func Generate

func Generate() (files []string, err error)

Generate is the generator entry point called by the meta generator.

func JavaScriptify

func JavaScriptify(str string, firstUpper bool, allowReserved bool) string

JavaScriptify, based on Goify makes a valid JavaScript identifier out of any string. It does that by removing any non letter and non digit character and by making sure the first character is a letter or "_". JavaScriptify produces a "CamelCase" version of the string, if firstUpper is true the first character of the identifier is uppercase otherwise it's lowercase.

Types

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator is the application code generator.

func (*Generator) Cleanup

func (g *Generator) Cleanup()

Cleanup removes all the files generated by this generator during the last invokation of Generate.

func (*Generator) Generate

func (g *Generator) Generate(api *design.APIDefinition) (_ []string, err error)

Generate produces the skeleton main.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址