Skip to content

Commit fbc85ee

Browse files
author
b
committed
release: 0.26, changed NULL_OUTPUT to [], and imposing now that updates be an array, just like outputs. Updated all tests
1 parent 057d15a commit fbc85ee

17 files changed

+395
-1633
lines changed

TODO.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Now
2+
// TODO: major change maybe brek all tests: change action identity in kingly to outputs: [], and updates: []
3+
// TODO: document, state updates MUST be an array if using the compiler or yed converter, outputs MUST be an array or null
4+
- zero values are used for action identity, and those are ([] and null), maybe future version add an option to change that
25
// TODO: Courtesan: in content-courtesan.js change .kuker to .courtesan (but last)
36
// TODO: Courtesan devtool: Ben hyperlink schneidermann - information seeking mantra
47
- overview first

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "kingly",
33
"sideEffects": false,
4-
"version": "0.25.0",
4+
"version": "0.26.0",
55
"description": "Extended Hierarchical State Transducer library",
66
"repository": {
77
"type": "git",

src/helpers.js

+4
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,10 @@ export function destructureEvent(obj) {
770770
return {eventName, eventData}
771771
}
772772

773+
export function formatUndefinedInJSON(obj){
774+
return JSON.stringify(obj, (key,value)=> {if (value === undefined) return "undefined"; else return value})
775+
}
776+
773777
export class KinglyError extends Error {
774778
// TODO: do something with the tracer too
775779
constructor(m, console, tracer) {

src/properties.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export const STATE_PROTOTYPE_NAME = 'State'; // !!must be the function name for
1313
// i.e. State
1414
export const NO_STATE_UPDATE = [];
1515
// NOTE : this really cannot be anything else than a falsy value, beware
16-
export const NO_OUTPUT = null;
16+
// TODO: check consequences of moving it to empty array
17+
export const NO_OUTPUT = [];
1718
export const ACTION_IDENTITY = function ACTION_IDENTITY(){
1819
return {
1920
outputs : NO_OUTPUT,

src/synchronous_fsm.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,8 @@ export function createStateMachine(fsmDef, settings) {
228228
tracer({
229229
type: MACHINE_CREATION_ERROR_MSG,
230230
trace: {
231-
error: e,
231+
info: e.errors,
232232
message: e.message,
233-
info: {fsmDef, settings},
234233
machineState: {cs: INIT_STATE, es: extendedState, hs: history}
235234
}
236235
});
@@ -318,7 +317,7 @@ export function createStateMachine(fsmDef, settings) {
318317
});
319318
console.warn(`The external event INIT_EVENT can only be sent when starting the machine!`)
320319

321-
return NO_OUTPUT
320+
return null
322321
}
323322

324323
const outputs = process_event(
@@ -391,7 +390,7 @@ export function createStateMachine(fsmDef, settings) {
391390
// CASE : There is no transition associated to that event from that state
392391
console.warn(`There is no transition associated to the event |${event}| in state |${current_state}|!`);
393392

394-
return NO_OUTPUT;
393+
return null;
395394
}
396395
}
397396

@@ -500,7 +499,7 @@ export function createStateMachine(fsmDef, settings) {
500499
const condition_checking_fn = function (extendedState_, event_data, current_state) {
501500
from = current_state || from;
502501
const predicate = guard.predicate || alwaysTrue;
503-
const predicateName = predicate.name || predicate.displayName || "";
502+
const predicateName = predicate.name || predicate.displayName || "<anonymous>";
504503
const to = guard.to;
505504
const shouldTransitionBeTaken = ((extendedState, event_data, settings) => {
506505
try {
@@ -605,7 +604,7 @@ export function createStateMachine(fsmDef, settings) {
605604
machineState: {cs: current_state, es: extendedState, hs: history}
606605
}
607606
});
608-
return {stop: false, outputs: NO_OUTPUT};
607+
return {stop: false, outputs: null};
609608
}
610609
};
611610
// TODO: remove that, I don't need that anymore
@@ -621,7 +620,7 @@ export function createStateMachine(fsmDef, settings) {
621620
};
622621
},
623622
function dummy() {
624-
return {stop: false, outputs: NO_OUTPUT};
623+
return {stop: false, outputs: null};
625624
}
626625
);
627626
});
@@ -634,9 +633,8 @@ export function createStateMachine(fsmDef, settings) {
634633
tracer({
635634
type: MACHINE_CREATION_ERROR_MSG,
636635
trace: {
637-
error: e,
638636
message: e.message,
639-
info: {fsmDef, settings},
637+
info: {fsmDef, settings, error: e},
640638
machineState: {cs: INIT_STATE, es: extendedState, hs: history}
641639
}
642640
});
@@ -719,7 +717,7 @@ export function makeWebComponentFromFsm({name, eventHandler, fsm, commandHandler
719717
const el = this;
720718
this.eventSubject = eventHandler;
721719
this.options = Object.assign({}, options);
722-
const NO_ACTION = this.options.NO_ACTION || NO_OUTPUT;
720+
const NO_ACTION = this.options.NO_ACTION || null;
723721

724722
// Set up execution of commands
725723
this.eventSubject.subscribe({

test/contracts.specs.js

-34
Original file line numberDiff line numberDiff line change
@@ -121,40 +121,6 @@ QUnit.test("fsmContracts(fsmDef): compound states - no init transition", functio
121121
], message);
122122
});
123123

124-
// NOTE: we canceled the contract about not having guards in initial transitions for compound states
125-
QUnit.skip("fsmContracts(fsmDef): compound states - invalid init transition", function exec_test(assert) {
126-
const fsmDef = {
127-
states: { A: { B: '' }, C: '' },
128-
events: ['ev'],
129-
transitions: [
130-
{ from: INIT_STATE, to: 'A', event: INIT_EVENT, action: ACTION_IDENTITY },
131-
{ from: 'C', to: 'B', event: 'ev', action: ACTION_IDENTITY },
132-
{ from: 'A', event: INIT_EVENT, guards: [{ to: 'B', action: ACTION_IDENTITY, predicate: () => true }] }
133-
],
134-
initialExtendedState: {},
135-
updateState: applyJSONpatch,
136-
};
137-
138-
const { isFulfilled, failingContracts } = fsmContractChecker(fsmDef, settings, fsmContracts);
139-
const failureInfo = failingContracts.find(x => x.name === validInitialTransitionForCompoundState.name);
140-
const { message, info } = failureInfo;
141-
const { entryTransitions } = info;
142-
assert.deepEqual(isFulfilled, false, `Fails at least one contract`);
143-
assert.deepEqual(entryTransitions.map(formatResult), [
144-
{
145-
"event": "init",
146-
"from": "A",
147-
"guards": [
148-
{
149-
"action": "ACTION_IDENTITY",
150-
"predicate": "predicate",
151-
"to": "B"
152-
}
153-
]
154-
}
155-
], message);
156-
});
157-
158124
QUnit.test("fsmContracts(fsmDef): compound states - invalid init transition - target states not within" +
159125
" hierarchy", function exec_test(assert) {
160126
const fsmDef = {

test/debug-settings-specs.js

-157
This file was deleted.

0 commit comments

Comments
 (0)