Skip to content

Instantly share code, notes, and snippets.

Avatar

Mateusz Burzyński Andarist

View GitHub Profile
View machine.js
Machine(
{
context: {
networkQuality: "good",
},
on: {
REPORT_NETWORK_QUALITY: {
actions: [
assign({
networkQuality: (_, ev) => ev.networkQuality,
View machine.js
Machine({
initial: 'fetching_user',
states: {
fetching_user: {
invoke: {
src: 'fetchUser',
onDone: [{
cond: 'hasUser',
target: 'fetching_resources'
}, {
View machine.js
// Available variables:
// Machine (machine factory function)
// assign (action)
// XState (all XState exports)
const fetchMachine = Machine({
id: 'fetch',
context: { attempts: 0 },
initial: 'idle',
View paginationMachine.js
// Copy and paste into https://statecharts.github.io/xstate-viz/
const paginationMachine = Machine(
{
id: "pagination",
initial: "empty",
on: {
UPDATE_PARAMS: "debouncing"
},
onDone: { actions: "hideMoreLoader" },
@Andarist
Andarist / cherry-pick_tree_example.md
Last active Jun 7, 2018
cherry-pick tree example
View cherry-pick_tree_example.md
Input:                 Output:

.                      .
├── es                 ├── effects
│   ├── effects.js     │   └── package.json
│   ├── index.js       ├── es
│   └── utils.js       │   ├── effects.js
├── lib                │   ├── index.js
│   ├── effects.js     │   └── utils.js
View gist:0d8efb15468bd9288ba1a7fa36f3e2a7
import nodeResolve from 'rollup-plugin-node-resolve'
import babel from 'rollup-plugin-babel'
import pkg from './package.json'
const mergeAll = objs => Object.assign({}, ...objs)
const commonPlugins = [
babel({
plugins: ['external-helpers'],
}),
View gist:83d1c29d9fd565d91d2c3feffbf8b3b1
// { type: 'A', payload: { timestamp: number } }
// { type: 'B', payload: { user_id: string } }
const parseA = data => ({ lastTimestamp: data * 1000 })
const parseB = data => ({ userId: data })
const serverMessageParser = (msg: SocketMessage): ParsedMessage => {
switch (msg.action) {
case 'A':
return parseA(msg.data)
View rating
sdk.sendEvent(CHAT_ID, {
type: 'annotation',
annotation_type: 'rating',
properties: {
rating: {
score: 0,
comment: 'You were very helpful',
},
},
})
View gist:0d53dbd238df3a5ed85567db6ef4f69c
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { AuthWebView } from '@livechat/chat.io-customer-auth';
import { init } from '@livechat/chat.io-customer-sdk'
export default class App extends React.Component {
componentDidMount() {
const sdk = init({ license: 100004225 })
sdk.on('connected', ({ chatsSummary, totalChats }) => {
console.log('on connected', { chatsSummary, totalChats })
View triggered_scenarios.js
trigger example:
{
type: "new_customer",
value: true
}
step: { action, outcomes }
action example:
You can’t perform that action at this time.