Documentation ¶
Index ¶
- Variables
- func Listen() (<-chan *Event, func())
- func ListenOn(evs chan<- *Event) func()
- func OnStorage(callback func(*Event)) func()
- type Event
- func (e *Event) JSValue() js.Value
- func (e *Event) Key() (string, bool)
- func (e *Event) New() (string, bool)
- func (e *Event) NewJSON(val interface{}) error
- func (e *Event) Old() (string, bool)
- func (e *Event) OldJSON(val interface{}) error
- func (e *Event) ParseURL() (*url.URL, error)
- func (e *Event) Storage() *Storage
- func (e *Event) URL() (string, bool)
- type Storage
- func (s *Storage) Clear()
- func (s *Storage) Get(key string) (string, bool)
- func (s *Storage) GetJSON(key string, val interface{}) error
- func (s *Storage) JSValue() js.Value
- func (s *Storage) Key(n int) (string, bool)
- func (s *Storage) Length() int
- func (s *Storage) Listen() (<-chan *Event, func())
- func (s *Storage) ListenOn(evs chan<- *Event) func()
- func (s *Storage) OnStorage(callback func(*Event)) func()
- func (s *Storage) Remove(key string)
- func (s *Storage) Set(key, val string)
- func (s *Storage) SetJSON(key string, val interface{}) error
Constants ¶
This section is empty.
Variables ¶
var ErrJSONNull = ErrNullJSON
ErrJSONNull exists for backward compatibility. TODO: remove in v0.3.0.
var ErrNullJSON = errors.New("null before json")
ErrNullJSON occurs when null is encountered before parsing JSON.
var ErrNullURL = errors.New("null before url")
ErrNullURL occurs when null is encountered before parsing a URL.
Functions ¶
func Listen ¶
func Listen() (<-chan *Event, func())
Listen creates a new channel of Events, similarly to OnStorage.
func ListenOn ¶
func ListenOn(evs chan<- *Event) func()
ListenOn attaches to an existing channel of Events, similarly to OnStorage.
func OnStorage ¶
func OnStorage(callback func(*Event)) func()
OnStorage adds an event listener for StorageEvents, invoking the provided callback.
The returned function will remove the callback and Release the associated js.Func.
Note: the storage event only occurs on other pages with access to the same Storage object.
Types ¶
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
Event represent a JavaScript StorageEvent.
StorageEvent properties are exposed in methods, but underlying Event properties may be accessed through JSValue as well.
func (*Event) Key ¶
Key retrieves the key associated with the Event. If the underlying value is null, the second return value will be false.
func (*Event) New ¶ added in v0.2.0
New returns the new value associated with the Event. If the underlying value is null, the second return value will be false.
func (*Event) NewJSON ¶ added in v0.2.0
NewJSON combines New with json.Unmarshal. The second argument should be a pointer, like with json.Unmarshal.
If the underlying property is null, ErrJSONNull is returned. Any other errors are from JSON parsing.
func (*Event) Old ¶ added in v0.2.0
Old returns the old value associated with the Event. If the underlying value is null, the second return value will be false.
func (*Event) OldJSON ¶ added in v0.2.0
OldJSON combines Old with json.Unmarshal. The second argument should be a pointer, like with json.Unmarshal.
If the underlying property is null, ErrJSONNull is returned. Any other errors are from JSON parsing.
func (*Event) ParseURL ¶ added in v0.2.0
ParseURL returns the URL associated with the Event, parsing it into a *url.URL for convenience. If the underlying value is null, the first and second return values will be nil and ErrNullURL, respectively.
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage represents a JavaScript Storage object.
func Local ¶
func Local() *Storage
Local retrieves a Storage value from the global property localStorage, or nil if no such property exists.
func Session ¶
func Session() *Storage
Session retrieves a Storage value from the global property sessionStorage, or nil if no such property exists.
func (*Storage) Get ¶ added in v0.2.0
Get retrieves the value associated with the given key in the Storage.
If the key does not exist in the Storage, the second return value is false.
func (*Storage) GetJSON ¶ added in v0.2.0
GetJSON combines Get with json.Unmarshal. The second argument should be a pointer, like with json.Unmarshal.
If the key does not exist in the Storage, ErrNullJSON is returned. Any other errors are from JSON parsing.
func (*Storage) Key ¶
Key retrieves the key of the Storage at the given index.
Key order is not guaranteed after mutations to the Storage.
func (*Storage) Listen ¶
Listen acts similarly to the package-level Listen function, but it filters events from this Storage object.
func (*Storage) ListenOn ¶
ListenOn acts similarly to the package-level ListenOn function, but it filters events from this Storage object.
func (*Storage) OnStorage ¶
OnStorage acts similarly to the package-level OnStorage function, but it filters events from this Storage object.
func (*Storage) Remove ¶ added in v0.2.0
Remove removes the given key from the Storage, if it exists.