router

package module
v0.0.0-...-6cc9f53 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2016 License: Apache-2.0 Imports: 3 Imported by: 0

README

gopherjqm-router

Router for jQuery Mobile applications written for GopherJS (Go compiled to JavaScript).

Why?

Several routers exist for single-page web applications. There's at least one for GopherJS, and there's at least one for jQuery Mobile, written in JavaScript. But there are none (to my knowledge) with bridge both worlds.

Design goals

The specific goals I intend this package to acheive are:

  • hashchange-driven router for jQuery Mobile apps. jquerymobile-router does this, but only for JavaScript code, and only for old versions of jQuery Mobile.
  • The router should be written in Go. humble-router does this, but does not support jQuery Mobile apps.
  • All source (.go and .js files) should be compilable to a single .js bundle. This plays nicely with both jQuery Mobile and GopherJS.
  • The router should support handlers written in either Go or JavaScript.

The latter point is specifically to bridge two realities: There are people like me, who hate writing JavaScript code, and there is the real world, where skilled web designers and front-end developers write code in JavaScript.

In "traditional" web apps, it's easy for back-end developers to user thier language of choice, and leave client-side JavaScript coding to the front-end guys. In a Single Page Application model, such as that provided by jQuery Mobile, no such division of coding technologies is traditionally available. This means that most SPAs are written entirely in a single language. This language is usually JavaScript, or sometimes another language, compiled to JavaScript.

One key goal of this project is to allow the traditional "client-side" development to use traditional tools, including JavaScript, while allowing the traditional "back end" work to be done in Go, while creating a single, unified output file (compiled JavaScript) which can run in the browser.

It might be enough to have a router written in Go, with only a JavaScript API, but once we've achieved this, supporting a Go API, and thus allowing request handlers written in Go, too, is a small step to take. This will also allow a choice, when it makes sense, between Go and JS for handler logic. And by making this a design goal from the beginning, I hope to ensure that both modes of operation (handlers in both Go and JS) are well supported.

License

This software is released under the terms of the Apache 2.0 license. See LICENCE.md, or read the full license.

Documentation

Rendered for js/wasm

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler func(*js.Object, *jquery.Event, *js.Object, Params) bool

type Param

type Param struct {
	Key   string
	Value string
}

Param is a single URL parameter, consisting of a key and a value.

type Params

type Params []Param

Params is a Param-slice, as returned by the router. The slice is ordered, the first URL parameter is also the first slice value. It is therefore safe to read values by the index.

type Router

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

func GetRouter

func GetRouter(elem *jquery.JQuery) *Router

GetRouter fetches a router object from the specified jQuery DOM element. If no router is set, nil is returned.

func New

func New(elem *jquery.JQuery) *Router

New creates a new Router object, and attaches it to the requested element

func (*Router) Handle

func (r *Router) Handle(path, event string, handler Handler) error

Jump to

Keyboard shortcuts

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