Created
April 27, 2012 05:33
-
-
Save andreyvit/2506197 to your computer and use it in GitHub Desktop.
Old RPC-based approach for building the UI (IcedCoffeeScript)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ 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