Skip to content
This repository has been archived by the owner on Oct 26, 2021. It is now read-only.

Commit

Permalink
FunctionBox dropdown to choose other examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre Medeiros committed Aug 3, 2014
1 parent 0d5f5c0 commit c6ecca4
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 17 deletions.
8 changes: 7 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,22 @@
+ DONE Refactor views: components OutputStream, InputStream, Stream
+ DONE Introduce virtual-dom for output stream view
+ DONE More generalized handling of examples
- TODO FunctionBox dropdown to choose other examples
+ DONE FunctionBox dropdown to choose other examples
>>> v0.1.0

- TODO Examples for Observable Instance Methods, such as debounce
>>> v0.2.0

- TODO RxMarbles title and proposition value
- TODO Webpage footer
>>> v0.2.1

- TODO Styling for dragging a marble
- z-depth and side arrows
- TODO Render each stream with a different regular polygon?
- TODO Render also the stream completion time marker?
>>> v0.2.2

- TODO Interactively add marbles to an InputStream
- TODO Interactively remove marbles from an InputStream
- TODO Add many examples to the dropdown
Expand Down
35 changes: 24 additions & 11 deletions dist/js/app.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/controllers/selected-example.coffee
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
Rx = require 'rx'
Examples = require 'rxmarbles/models/examples'
FunctionBox = require 'rxmarbles/views/function-box'

#
# Exports a stream of the currently selected example.
#

selectedExampleKey$ = Rx.Observable.just("concat")
selectedExampleKey$ = FunctionBox.getSelected$().startWith("concat")

selectedExample$ = selectedExampleKey$
.map((key) ->
Expand Down
18 changes: 15 additions & 3 deletions src/views/function-box.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ h = require 'hyperscript'
Rx = require 'rx'
Examples = require 'rxmarbles/models/examples'

selected$ = new Rx.Subject()

renderSelectOptionsArray = (examples) ->
options = []
for key,example of examples
Expand All @@ -21,16 +23,26 @@ setupClickBehavior = (functionBoxElement, selectElement) ->
selectElement.dispatchEvent(event)
return true
)
# We should use Rx.Observable.from(selectElement, "change") but it doesnt work
selectElement.addEventListener("change", (ev) ->
selected$.onNext(ev.target.value)
return true
)
return true

module.exports = {
render: (label) ->
getSelected$: ->
return selected$

render: (example) ->
functionBoxElement = h("div.function-box", [
h("span.function-box-label", label)
h("span.function-box-label", example.label)
selectElement = h("select", renderSelectOptionsArray(Examples))
h("div.function-box-dropdown", [
dropdown = h("div.function-box-dropdown", [
h("span.function-box-dropdown-arrow")
])
])
selectElement.value = example.key
setupClickBehavior(functionBoxElement, selectElement)
return functionBoxElement
}
2 changes: 1 addition & 1 deletion src/views/sandbox.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ createFunctionBoxElement = ->
SelectedExample = require 'rxmarbles/controllers/selected-example'
return Utils.renderObservableDOMElement(
SelectedExample.stream
.map((example) -> FunctionBox.render(example.key))
.map((example) -> FunctionBox.render(example))
)

createOutputDiagramElement = ->
Expand Down

0 comments on commit c6ecca4

Please sign in to comment.