Skip to content

Instantly share code, notes, and snippets.

const scxml = require('scxml');
scxml.pathToModel("transient.xml",function(err,model){
if (err) throw err;
model.prepare(function(err, fnModel) {
if(err) throw err;

I'm wondering if it would be useful to provide a way to have guards be kept out of the state machine, to keep it all "pure function".

The way I thought it might work would be to add a parameter to the transition to specify the value of any guards. The guards would always be optional, but would of course influence the outcome. Here's a machine with a named guard (I use 'guard' instead of 'cond' because I like statechart terminology better than scxml):

m = Machine({
  foo: {
    on: {
      A: bar,
      B: {
@mogsie
mogsie / StateMachine.js
Last active January 9, 2018 23:00
Wraps the xstate instance and a "current state". The transition function deals with calling side effects too.
class StateMachine {
constructor(machine, object) {
this.machine = machine;
this.object = object;
this.state = null;
this.timers = {}
}
event(event) {
const maybeNextState = ! this.state ? this.machine.initialState : this.machine.transition(this.state, event);

I thought I'd weigh in on how I see guards in "stateless" statecharts They're totally deterministic, given the same evaluations of the guards.

When I write tests for my state machines, I set it in an initial state, I send it a sequence of events, and ensure that the guards evaluate to certain values. The state machine simulates timeouts so it runs through all the states almost instantaneously. When it's done, I "expect" a particular side effect to have happened.

So for example, given a simple state machine with states X and Y, and the "foo" event makes it do something:

 X          foo                 Y
           ------>           entry / dosomething
                             exit / stopdoingsometing
@mogsie
mogsie / OpenSearch.mediawiki
Last active August 29, 2015 14:21
Raw source of the MediaWiki source of the OpenSearch spec as of 23 May 2015

Notice

Overview

This document defines the OpenSearch description document, the OpenSearch Query element, the OpenSearch URL template syntax, and the OpenSearch response elements. Collectively these formats may be referred to as "OpenSearch 1.1" or simply "OpenSearch".

Search clients can use OpenSearch description documents to learn about the public interface of a search engine. These description documents contain parameterized URL templates that indicate how the search client should make search requests. Search engines can use the OpenSearch response elements to add search metadata to results in a variety of content formats.

@mogsie
mogsie / xyzzy.scxml
Created April 15, 2015 18:06
Test SCXML
<scxml initial="initial-default" version="1.0" xmlns="http://www.w3.org/2005/07/scxml"><!-- node-size-and-position x=0 y=0 w=778,39 h=1265 -->
<datamodel><!--
This is the object we call out to (synchronously) ask the UI
for information about the state of the UI (to e.g. make
decisions. E.g. if the user only typed one letter, we might
want to not perform a "suggest" (and therefore not make a
transition).
-->
<data id="actions"></data>
<data id="guards"></data>
@mogsie
mogsie / gedcom-json.md
Last active January 2, 2016 00:09
My proposal of represengin a single GEDCOM entry (i.e. one level 0 node) as a JSON structure.

GEDCOM is a well structured format. Defining a "standard" way to represent a GEDCOM node in JavaScript memory is useful, because it allows tools to be built in JavaScript space that can work with these JavaScript representations. For example, an editor can be crafted that is able to make edits in a browser to such a structure; while another tool might be able to use the information to present a pleasing web page, while a third tool might be able to traverse links between documents to make a pedigree report.

Similarities

Both formats are hierarchical:

  • GEDCOM is a hierarchical file format, although the Wikipedia page doesn't mention the word "hierarchy" at all; only "indentation level". Indentation level "1" items are usually followed by one or more indentation level 2 items; which are
  • JSON is in fact a hierarchical format, in that nodes contain other nodes.

Both formats are ordered:

Erik Mogensen

Chief Architect Vizrt Online

How did I learn REST?

Context: SOAP, RMI, RPC, CORBA

2004: "Use HTTP the way it was meant to be used"

Done

@mogsie
mogsie / alternative-to-routing-frameworks.md
Last active December 23, 2015 13:39
My 5-in-5 presentation for REST Fest 2013

Erik Mogensen

Chief Architect, Vizrt

An alternative to template based routing?

Traditional routing

GET /user/:id