daisho
Version:
Modular dashboard framework
155 lines (120 loc) • 3.74 kB
text/coffeescript
import El from 'el.js'
import Hanzo from 'hanzo.js'
import Tween from 'es-tween'
import {raf} from 'es-raf'
import akasha from 'akasha'
import Events from './events'
import Services from './services'
import Views from './views'
import blueprints from './blueprints'
import mediator from './mediator'
import utils from './utils'
import currencies from 'shop.js-util/src/data/currencies'
animate = (time) ->
raf animate
Tween.update time
raf animate
reservedTags = {}
# Monkey patch el.js so all registration can be validated
El.Views.Form.register = El.Views.View.register = ->
if reservedTags[]
throw new Error "#{@tag} is reserved:", reservedTags[]
r = new @
= r.tag
reservedTags[] = @
return r
Views.register()
export default class Daisho
: El
: Views
: Views.Graphics
: Services
: Events
: mediator
: utils
: currencies
client: null
data: null
settings: null
modules: null
debug: false
services: null
utils: Daisho.utils
currencies: currencies
countries: []
constructor: (url, modules, , , debug = false) ->
= new Hanzo.Api
debug: debug
endpoint: url
= debug
=
menu: new Services.Menu @, debug
page: new Services.Page @, debug
command: new Services.Command @, debug
navigation: new Services.Navigation @, debug
.page.mount = =>
.apply @, arguments
.page.update = =>
.apply @, arguments
.addBlueprints k,v for k,v of blueprints
= modules
lastChecked = akasha.get 'lastChecked'
countries = akasha.get 'countries'
.push.apply , countries
Daisho.countries =
lastChecked = utils.date.renderDate(new Date(), utils.date.rfc3339)
.library.daisho(
hasCountries: !!countries && countries.length != 0
lastChecked: utils.date.renderDate(lastChecked || '2000-01-01', utils.date.rfc3339)
).then (res) =>
if res.countries?
.length = 0
.push.apply , res.countries
akasha.set 'countries',
akasha.set 'lastChecked', lastChecked
.set 'countries',
.catch (err) =>
console.log 'Could not load countries data.', err
start: ->
modules =
for k, module of modules
if typeof module == 'string'
# do something
else
new module @, .page, .menu, .command, .navigation
.page.start()
mount: (tag, opts = {}) ->
isHTML = tag instanceof HTMLElement
if isHTML
tagName = tag.tagName.toLowerCase()
else
tagName = tag
if !opts.client
opts.client =
if !opts.data
if !.get tagName
.set tagName, {}
opts.data = .ref tagName
if !opts.parentData
opts.parentData =
if !opts.services
opts.settings =
if !opts.services
opts.services =
if !opts.util
opts.utils =
if !opts.currencies
opts.currencies =
if !opts.countries
opts.countries =
if !opts.mediator
opts.mediator = Daisho.mediator
if !opts.daisho
opts.daisho = @
if typeof tag == 'string'
El.mount tag, opts
else if isHTML
El.mount tag, tagName, opts
scheduleUpdate: ->
El.scheduleUpdate.apply El, arguments