Skip to content

Instantly share code, notes, and snippets.

@andreyvit
Created April 27, 2012 05:33
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 andreyvit/2506197 to your computer and use it in GitHub Desktop.
Save andreyvit/2506197 to your computer and use it in GitHub Desktop.
Old RPC-based approach for building the UI (IcedCoffeeScript)
module.exports = class MainWindowUI
show: (callback) ->
@window = new UIWindow 'MainWindow',
addProjectButton: new UIButton
click: =>
LR.log.fyi "Clicked Add Project button"
removeProjectButton: new UIButton
click: =>
LR.log.fyi "Clicked Remove Project button"
await @window.create defer(err)
await @window.show defer(err)
callback(null)
{ EventEmitter } = require 'events'
class UIObject extends EventEmitter
constructor: (@options) ->
@handle = null
@_init()
_init: ->
_createBindings: -> {}
class UIControl extends UIObject
_init: ->
if @options.click
@on 'click', @options.click
delete @options.click
_createBindings: ->
click: =>
@emit 'click'
class UIButton extends UIControl
class UIWindow extends UIObject
constructor: (@className, controls={}) ->
@controls = []
@add controls
add: (name, control) ->
if Object.isObject name
for own k, v of name
@add k, v
return
control.name = name
@controls.push control
this[name] = control
create: (callback) ->
bindings = {}
objects = {}
bindings.window = @_createBindings()
objects.window = this
for control in @controls
bindings[control.name] = control._createBindings()
objects[control.name] = control
await C.ui.createWindow {
@className
bindings
}, defer(err, response)
for own k, _ of bindings
objects[k].handle = response[k]
callback(null)
show: (callback) ->
C.ui.showWindow { window: @handle }, callback
module.exports = {
UIObject
UIControl
UIButton
UIWindow
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment