Categorygithub.com/huckridgesw/hvue
modulepackage
0.0.0-20181030184406-02dc3ed95601
Repository: https://github.com/huckridgesw/hvue.git
Documentation: pkg.go.dev

# README

Intro

hvue is a GopherJS and wasm wrapper for the Vue Javascript framework.

This (the "master" branch) is the go/wasm + GopherJS version. It uses gopherwasm to provide a compatability layer between go/wasm and GopherJS. go/wasm is patterned on GopherJS, but doesn't have all of its capabilities and language-specific "magic". In particular, go/wasm doesn't have GopherJS's "dual struct/object" magic, which allows you to embed a *js.Object in a struct, define struct fields with js:"jsName" tags, and have the compiler automatically change references to those fields into references to fields in the inner *js.Object. So to access a JavaScript object in go/wasm, you have to use a "naked" js.Value and either use thing.Get("jsField") (and related functions) everywhere (ew) or write access functions (less ew). You can also write GopherJS in the same style, and gopherwasm creates a compatability layer so the go/wasm style compiles under GopherJS.

The GopherJS-only version is tagged as v1, and also as gopherjs.

The wasm branch still exists, because I shared it pretty widely, and I want those links to keep working for a while.

So if you want to use the go/wasm code, and/or also use this exact code in GopherJS, use this branch. If you want the GopherJS-only code, use the v1 or gopherjs branch. Click on over to the README in that branch for installation instructions. They may need modification, since they still date to when hvue's "master" branch was GopherJS-only.

Install

Install Go 1.11

See https://golang.org/dl/.

Install hvue

(Side note: If you skipped it, please make sure you've read the Intro above about the difference between this (the go/wasm + GopherJS code), and previous GopherJS-only versions.)

cd path/to/github.com # in your $GOPATH
mkdir huckridgesw
cd huckridgesw
git clone [email protected]:HuckRidgeSW/hvue.git

Examples & Demos

Overview

Generally speaking, the examples follow the examples in the Vue guide. Some don't, because the Guide has changed since I wrote the examples. But most of them do.

01-introduction has examples from the Vue Introduction page.

02-lifecycle demos Vue lifecycle hooks but does not correspond to any specific example on that page.

03-computed-basic and 04-computed-with-setter have examples from Computed Properties and Watchers.

And so on. Links are in the code.

Running the examples

GopherJS

cd path/to/github.com/huckridgesw/hvue
echo "var hvue_wasm = false;" > examples/maybe_wasm.js
gopherjs serve github.com/huckridgesw/hvue # listens on 8080

and then

WASM

cd path/to/github.com/huckridgesw/hvue
echo "var hvue_wasm = true;" > examples/maybe_wasm.js
go run examples/server/main.go # Listens on 8081
cd examples/??-???? # some examples directory
GOARCH=wasm GOOS=js go build -o ${PWD##*/}.wasm main.go # compile wasm

and then

Remember to recompile after any changes. There's no facility yet to auto-build (a-la gopherjs build -w or gopherjs serve).

Switching from GopherJS to WASM and back

  • Do the appropriate "echo "var hvue_wasm = ?;" > examples/maybe_wasm.js. (See above.)
  • Be sure to do "shift-cmd-R" (Chrome, macOS; other browsers / OSes will vary) to reload without using the cache, to get the new maybe_wasm.js and/or new wasm. (Actually I'm not sure you need that to get new wasm, since it's loaded via an explicit fetch() call, but it's probably not a bad idea.) Alternatively, in Chrome you can open the developer console, go to the network tab, and check "disable cache". (AIUI only works while said console window is open.)

GoDoc

http://godoc.org/github.com/HuckRidgeSW/hvue

# Packages

No description provided by the author

# Functions

Activated lets you define a hook for the activated lifecycle action.
BeforeCreate lets you define a hook for the beforeCreate lifecycle action.
BeforeDestroy lets you define a hook for the beforeDestroy lifecycle action.
BeforeMount lets you define a hook for the beforeMount lifecycle action.
BeforeUpdate lets you define a hook for the beforeUpdate lifecycle action.
Bind specifies the js{bind} directive hook function.
Component is used in NewVM to define a local component, within the scope of another instance/component.
ComponentUpdated specifies the js{componentUpdated} directive hook function.
Computed defines name as a computed property.
ComputedWithGetSet defines name as a computed property with explicit get & set.
Created lets you define a hook for the created lifecycle action.
Data sets a single data field.
DataFunc defines a function that returns a new data object.
DataS sets the object `goValue` as the entire contents of the vm's data field.
Deactivated lets you define a hook for the deactivated lifecycle action.
Default gives the default for a prop.
DefaultFunc sets a function that returns the default for a prop.
Destroyed lets you define a hook for the destroyed lifecycle action.
El sets the vm's el slot.
Inserted specifies the js{inserted} directive hook function.
No description provided by the author
No description provided by the author
Method adds a single function as a "method" on a vm.
MethodsOf sets up vm.methods with the exported methods of the type that t is an instance of.
Mounted lets you define a hook for the mounted lifecycle action.
NewArray is a utility function for creating a new JS array.
No description provided by the author
NewComponent defines a new Vue component.
NewDirective creates a new directive.
NewObject is a utility function for creating a new JavaScript Object of type js.Value.
NewVM returns a new vm, analogous to Javascript `new Vue(...)`.
PropObj defines a complex prop slot called `name`, configured with Types, Default, DefaultFunc, and Validator.
Props defines one or more simple prop slots.
Push appends any to the end of o, in place.
Set is a wrapper for js{Vue.set}.
Short allows you to use the "function shorthand" style of directive definition, when you want the same behavior on bind and update, but don't care about the other hooks.
Template defines a template for a component.
Types configures the allowed types for a prop.
Unbind specifies the js{unbind} directive hook function.
Update specifies the js{update} directive hook function.
Updated lets you define a hook for the updated lifecycle action.
Validator functions generate warnings in the JS console if using the vue.js development build.
No description provided by the author

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

Required specifies that the prop is required.

# Structs

Config is the config object for NewVM.
Directive wraps a js{Vue.directive} object.
DirectiveBinding wraps the js{binding} slot of the directive hook argument.
DirectiveConfig is the config object for configuring a directive.
Event wraps the event object sent to v-on event handlers.
No description provided by the author
PropConfig is the config object for Props.
VM wraps a js Vue object.

# Type aliases

No description provided by the author
The type of function passed to SetDataFunc, to initialize the fields for a new data object in a Vue component.
No description provided by the author
Modeled on GopherJS's js.M, also a map[string]interface{}.
No description provided by the author