Skip to content

Instantly share code, notes, and snippets.

@Struchu
Last active June 7, 2019 13:32
Show Gist options
  • Save Struchu/848be1c1e875656d6ef66d2a8b06ab5f to your computer and use it in GitHub Desktop.
Save Struchu/848be1c1e875656d6ef66d2a8b06ab5f to your computer and use it in GitHub Desktop.
Reactive Coordinators proof of concept
import blessed from 'blessed';
import { fromEvent, fromEventPattern } from 'rxjs';
import { take } from 'rxjs/operators';
// Helper that creates Observable from Blessed.js input.
import { fromInput } from './form';
export default function(viewModel, disposeBag) {
const view = blessed.form({/* Init the view. */});
const loginInput = blessed.textbox({/* Init input for user login. */});
const passwordInput = blessed.textbox({/* Init password input. */});
const submitButton = blessed.button({/* Init submit button. */});
const messageBox = blessed.message({/* Init message box for displaying error. */});
// Invoke View Model.
const { outputs: { token, error } } = viewModel(
{
email: fromInput(loginInput),
password: fromInput(passwordInput),
},
fromEvent(submitButton, 'press'),
);
// Subscribe to error messages and place subscription in dispose bag.
disposeBag.add(error.subscribe(messageBox.error.bind(messageBox)));
return {
outputs: {
// Dismiss view when 'escape' key is hit.
dismiss: fromEventPattern(
h => { view.key('escape', h); },
h => { view.unkey('escape', h); },
),
login: token.pipe(take(1)),
},
view,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment