Core Moxie Modules¶
When developing with Backbone.js we identify common code and move that into the core
module.
core/collections/MoxieCollection¶
Our base Collection providing some common methods we’re using throughout our applications. To create a new collection using MoxieCollection
simply extend it.
-
MoxieCollection.
getAsync
(key[, options, retry])¶ We found that a common usecase for us was waiting for a “fetch” or somesuch async call to be made before we could confidently call
get
to get our object. Since we were doing this quite often we createdgetAsync
. This allows you to wait for an event to fire on your collection before callingget
on the key. Passing a success callback which will receive the object requested as the first argument.Arguments: - key – The
id
of the model you want to access from the collection. SeeBackbone.Model.idAttribute
. - options (object) –
The following optional arguments can be passed in the options argument
success
: Called when the get has succeeded, this function will be called with the object returned from the collection as the argument.failure
: Called if thekey
cannot be found in the collection.pendingEvent
: defaultreset
- The event you want getAsync to wait for before callingsuccess
.
- retry (boolean) – Used to prevent repeated callbacks occuring.
- key – The
core/media¶
Simple module which presents an API to determine which media queries are active
on the document
at a particular time.
-
media.
isTablet
¶ Does our media query suggest the
document
is being rendered in a tablet style layout. This also applies for desktop’s and any device with significant width.
-
media.
isPhone
¶ Are we being rendered on a device with a small width suggesting a phone.
core/views/MapView¶
Base view for rendering a Map with a collection of Points of Interest (POICollection) on it.
-
class
MapView
([options])¶ Accepts all the usual
Backbone.View
arguments. As well as:Arguments: - options.fullScreen – Should this Map have the full-screen class to render at 100% height?
- options.interactiveMap – Should the map allow user interaction e.g.
touch and drag the map about. If this is
falsy or the map is rendered in phone view
then click events on the map will be fired as
mapClick
on theMapView
object.
-
MapView.
setCollection
(collection)¶ Update the MapView, removing any points currently rendered and place pointers for the new
collection
.Arguments: - collection – The new
Backbone.Collection
to be rendered. Models within this collection should havelat
and ``lon` attribute in order for points to be placed.
- collection – The new