Skip to content

Instantly share code, notes, and snippets.

View sukima's full-sized avatar

Devin Weaver sukima

View GitHub Profile
@sukima
sukima / machine.js
Last active May 9, 2024 23:55
Generated by XState Viz: https://xstate.js.org/viz
const parseScannedData =
(context, event) => {
return (callback) => {
// This should be something that gets the json:
let { json } = {} // doSomethingAsync();
let isValid = Array.isArray(json);
if (!isValid) {
callback({ type: 'SCAN_ERROR' });
} else {
@sukima
sukima / machine.js
Created April 16, 2020 03:21
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@sukima
sukima / -state-machine.js
Last active April 13, 2020 15:36
Ember-XState example
import { Machine } from 'xstate';
// This machine is completely decoupled from Ember
export const toggleMachine = Machine({
id: 'toggle',
context: {
/* some data */
},
initial: 'inactive',
states: {
@sukima
sukima / controllers.application\.js
Last active April 11, 2020 21:56
Class Decorators Example
import Controller from '@ember/controller';
function log(target) {
return class logWrapped extends target {
constructor(...args) {
console.log('Here', ...args);
super(...args);
}
}
}
@sukima
sukima / -private\.js
Last active May 9, 2024 23:51
XState Decorators
export const CURRENT_STATE = Symbol('current state');
export const STATE_PROPS = Symbol('state properties');
export const MACHINE = Symbol('machine');
export const LISTENERS = Symbol('listeners');
export const CONFIG = Symbol('config');
export const CONTEXT = Symbol('context');
@sukima
sukima / machine.js
Last active May 9, 2024 23:55
Generated by XState Viz: https://xstate.js.org/viz
function createMachine() {
return Machine({
id: 'example-form-manager',
type: 'parallel',
context: {
canSelectNone: true,
advancedProtocol: '',
ip4Address: '',
ip6Address: ''
},
@sukima
sukima / machine.js
Created April 3, 2020 18:48
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@sukima
sukima / machine.js
Created March 26, 2020 22:27
Generated by XState Viz: https://xstate.js.org/viz
//import { Machine, assign } from 'xstate';
//import { isPresent } from '@ember/utils';
function createMachine() {
return Machine({
id: 'rule-group-data-manager',
initial: 'prefetching',
context: {
items: [],
clauses: null,
@sukima
sukima / machine.js
Created March 24, 2020 22:03
Generated by XState Viz: https://xstate.js.org/viz
function createMachine() {
return Machine({
id: 'example-form-manager',
type: 'parallel',
context: {
canSelectNone: true,
ip4Address: '',
ip6Address: ''
},
states: {
@sukima
sukima / components.network-form\.js
Last active July 20, 2022 20:07
FormManagerExample
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { guidFor } from '@ember/object/internals';
import { createMachine } from '../utils/-state-machine';
const { interpret, assign } = XState;
export default class extends Component {
@tracked state;