Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@designeng
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save designeng/10068503 to your computer and use it in GitHub Desktop.
Save designeng/10068503 to your computer and use it in GitHub Desktop.
define [
"underscore"
"when"
], (_, When) ->
return (options) ->
extend = (componentDefinition, wire) ->
When.promise (resolve) ->
if !componentDefinition.options.with
throw "no 'with' option specified"
if componentDefinition.options.module
wire.loadModule(componentDefinition.options.module).then (Module) ->
_keys = _.keys componentDefinition.options.with
_values = _.values componentDefinition.options.with
class Extended extends Module
# no new fields yet
i = 0
for key in _keys
Extended::[key] = _values[i]
i++
resolve Extended
, (error) ->
reject error
else
throw "no 'module' option specified"
extendWithFactory = (resolver, componentDefinition, wire) ->
extend(componentDefinition, wire).then (extended) ->
resolver.resolve(extended)
, (error) ->
console.error error.stack
context:
ready: (resolver, wire) ->
resolver.resolve()
factories:
extend: extendWithFactory
switchItemView:
extend:
module: "controls/switch/item/switchItemView"
with:
itemSelectedClass: "switchItem__selected"
itemFocusedClass: "switchItem__focused"
switcher:
create:
module: "controls/switch/switchControl"
args:
name: "switcher"
properties:
itemView: {$ref: 'switchItemView'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment