Skip to content

Instantly share code, notes, and snippets.

@alltom
Last active October 19, 2016 07:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alltom/05e768f77fa27758bbe0972b5e8eecf5 to your computer and use it in GitHub Desktop.
Save alltom/05e768f77fa27758bbe0972b5e8eecf5 to your computer and use it in GitHub Desktop.
# [Two-Man Rule](https://en.wikipedia.org/wiki/Two-man_rule)
## Model
Create two locks.
```
commit @model
[#lock name: "Lock 1", locked: true]
[#lock name: "Lock 2", locked: true]
```
Unlock locks when their key is turned.
```
search @event @model
[#turn-key name]
lock = [#lock name]
commit @model
lock.locked := false
```
Emit an event when both locks have been unlocked.
```
search @model
[#lock name: "Lock 1", locked: false]
[#lock name: "Lock 2", locked: false]
commit @event
[#all-unlocked]
```
## View
Display buttons for each of the locks.
```
search @model
[#lock name locked]
state = if locked = true then "Locked" else "Unlocked"
bind @browser
[#button name, text: "{{name}}: {{state}}", sort: name]
```
When a button is clicked, turn its key.
```
search @event @browser
[#click element: [#button name]]
commit @event
[#turn-key name]
```
Display a crazy awesome message when everything's unlocked
```
search @event
[#all-unlocked]
commit @browser
[#h1 text: "The door is open!", sort: "ZZZ"]
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment