Skip to content

Commit

Permalink
Merge pull request #9 from Yoctol/naming
Browse files Browse the repository at this point in the history
rename XState to Xstate
  • Loading branch information
chentsulin authored Aug 16, 2018
2 parents 44b45b6 + 25b34f2 commit f6b3bcd
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 51 deletions.
8 changes: 4 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
- [new] Implement basic usage:

```js
const bottenderXState = require('bottender-xstate');
const bottenderXstate = require('bottender-xstate');

const config = {
key: 'light',
Expand Down Expand Up @@ -33,7 +33,7 @@ const config = {
},
};

const mapContextToXStateEvent = () => 'TIMER';
const mapContextToXstateEvent = () => 'TIMER';

const actionMap = {
enterGreen: context => context.sendText('enter green'),
Expand All @@ -45,9 +45,9 @@ const actionMap = {
};

bot.onEvent(
bottenderXState({
bottenderXstate({
config,
mapContextToXStateEvent,
mapContextToXstateEvent,
actionMap,
})
);
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ npm install bottender-xstate

| Param | Type | Description |
| ----------------------- | -------------- | -------------------------------------------- |
| config | `XStateConfig` | Config to be passed to xstate. |
| mapContextToXStateEvent | `Function` | Mapper for create xstate event from context. |
| config | `XstateConfig` | Config to be passed to xstate. |
| mapContextToXstateEvent | `Function` | Mapper for create xstate event from context. |
| actionMap | `Object` | Map of named actions. |
| guards | `Object` | Map of named guards. |
| onEvent | `Function` | Callback to be called when trigger event. |
| onAction | `Function` | Callback to be called when trigger action. |

```js
const bottenderXState = require('bottender-xstate');
const bottenderXstate = require('bottender-xstate');

const config = {
key: 'light',
Expand Down Expand Up @@ -54,7 +54,7 @@ const config = {
},
};

const mapContextToXStateEvent = () => 'TIMER';
const mapContextToXstateEvent = () => 'TIMER';

const actionMap = {
enterGreen: context => context.sendText('enter green'),
Expand All @@ -66,9 +66,9 @@ const actionMap = {
};

bot.onEvent(
bottenderXState({
bottenderXstate({
config,
mapContextToXStateEvent,
mapContextToXstateEvent,
actionMap,
})
);
Expand Down
8 changes: 4 additions & 4 deletions examples/basic.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { ConsoleBot } = require('bottender');

const bottenderXState = require('../src');
const bottenderXstate = require('../src');

const bot = new ConsoleBot();

Expand Down Expand Up @@ -32,7 +32,7 @@ const config = {
},
};

const mapContextToXStateEvent = () => {
const mapContextToXstateEvent = () => {
const event = 'TIMER';

console.log(`Event: ${event}`);
Expand All @@ -50,9 +50,9 @@ const actionMap = {
};

bot.onEvent(
bottenderXState({
bottenderXstate({
config,
mapContextToXStateEvent,
mapContextToXstateEvent,
actionMap,
})
);
Expand Down
8 changes: 4 additions & 4 deletions examples/hierarchical.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { ConsoleBot } = require('bottender');

const bottenderXState = require('../src');
const bottenderXstate = require('../src');

const bot = new ConsoleBot();

Expand Down Expand Up @@ -57,7 +57,7 @@ const config = {
},
};

const mapContextToXStateEvent = () => {
const mapContextToXstateEvent = () => {
const event = Math.random() > 0.5 ? 'TIMER' : 'PED_TIMER';

console.log(`Event: ${event}`);
Expand All @@ -81,9 +81,9 @@ const actionMap = {
};

bot.onEvent(
bottenderXState({
bottenderXstate({
config,
mapContextToXStateEvent,
mapContextToXstateEvent,
actionMap,
})
);
Expand Down
8 changes: 4 additions & 4 deletions examples/history.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { ConsoleBot } = require('bottender');

const bottenderXState = require('../src');
const bottenderXstate = require('../src');

const bot = new ConsoleBot();

Expand Down Expand Up @@ -35,7 +35,7 @@ const config = {

let count = 0;

const mapContextToXStateEvent = () => {
const mapContextToXstateEvent = () => {
count += 1;

let event;
Expand Down Expand Up @@ -69,9 +69,9 @@ const actionMap = {
};

bot.onEvent(
bottenderXState({
bottenderXstate({
config,
mapContextToXStateEvent,
mapContextToXstateEvent,
actionMap,
})
);
Expand Down
8 changes: 4 additions & 4 deletions examples/named_guards.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { ConsoleBot } = require('bottender');

const bottenderXState = require('../src');
const bottenderXstate = require('../src');

const bot = new ConsoleBot();

Expand Down Expand Up @@ -38,7 +38,7 @@ const config = {
},
};

const mapContextToXStateEvent = () => {
const mapContextToXstateEvent = () => {
const event = 'TIMER';

console.log(`Event: ${event}`);
Expand All @@ -56,9 +56,9 @@ const actionMap = {
};

bot.onEvent(
bottenderXState({
bottenderXstate({
config,
mapContextToXStateEvent,
mapContextToXstateEvent,
actionMap,
guards: {
randomly: () => {
Expand Down
8 changes: 4 additions & 4 deletions examples/parallel.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { ConsoleBot } = require('bottender');
const randomItem = require('random-item');

const bottenderXState = require('../src');
const bottenderXstate = require('../src');

const bot = new ConsoleBot();

Expand Down Expand Up @@ -77,7 +77,7 @@ const config = {
},
};

const mapContextToXStateEvent = () => {
const mapContextToXstateEvent = () => {
const event = randomItem([
'TOGGLE_BOLD',
'TOGGLE_UNDERLINE',
Expand Down Expand Up @@ -114,9 +114,9 @@ const actionMap = {
};

bot.onEvent(
bottenderXState({
bottenderXstate({
config,
mapContextToXStateEvent,
mapContextToXstateEvent,
actionMap,
})
);
Expand Down
28 changes: 14 additions & 14 deletions src/__tests__/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const bottenderXState = require('../');
const bottenderXstate = require('../');

const config = {
key: 'light',
Expand Down Expand Up @@ -28,7 +28,7 @@ const config = {
},
};

const mapContextToXStateEvent = () => 'TIMER';
const mapContextToXstateEvent = () => 'TIMER';

const actionMap = {
enterGreen: context => context.sendText('enter green'),
Expand All @@ -40,9 +40,9 @@ const actionMap = {
};

it('should call match actions', async () => {
const handler = bottenderXState({
const handler = bottenderXstate({
config,
mapContextToXStateEvent,
mapContextToXstateEvent,
actionMap,
});

Expand All @@ -59,9 +59,9 @@ it('should call match actions', async () => {
});

it('should call setState with xstate state value', async () => {
const handler = bottenderXState({
const handler = bottenderXstate({
config,
mapContextToXStateEvent,
mapContextToXstateEvent,
actionMap,
});

Expand All @@ -85,9 +85,9 @@ it('should call setState with xstate state value', async () => {
});

it('should load state from session', async () => {
const handler = bottenderXState({
const handler = bottenderXstate({
config,
mapContextToXStateEvent,
mapContextToXstateEvent,
actionMap,
});

Expand Down Expand Up @@ -123,9 +123,9 @@ it('should load state from session', async () => {

it('should call onEvent with event', async () => {
const onEvent = jest.fn();
const handler = bottenderXState({
const handler = bottenderXstate({
config,
mapContextToXStateEvent,
mapContextToXstateEvent,
actionMap,
onEvent,
});
Expand All @@ -143,9 +143,9 @@ it('should call onEvent with event', async () => {

it('should call onAction with action name', async () => {
const onAction = jest.fn();
const handler = bottenderXState({
const handler = bottenderXstate({
config,
mapContextToXStateEvent,
mapContextToXstateEvent,
actionMap,
onAction,
});
Expand All @@ -164,7 +164,7 @@ it('should call onAction with action name', async () => {

it('should support named guards', async () => {
const someCond = jest.fn(() => true);
const handler = bottenderXState({
const handler = bottenderXstate({
config: {
key: 'light',
initial: 'green',
Expand All @@ -181,7 +181,7 @@ it('should support named guards', async () => {
},
},
},
mapContextToXStateEvent,
mapContextToXstateEvent,
actionMap,
guards: {
someCond,
Expand Down
14 changes: 7 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const warning = require('warning');
const { State, Machine } = require('xstate');

function bottenderXState({
function bottenderXstate({
config,
mapContextToXStateEvent,
mapContextToXstateEvent,
actionMap,
guards = {},
onEvent,
Expand All @@ -12,12 +12,12 @@ function bottenderXState({
return async context => {
const machine = Machine(config, { guards });

const contextXState = context.state.xstate;
const contextXstate = context.state.xstate;

const currentState = contextXState
? new State(contextXState.value, contextXState.historyValue)
const currentState = contextXstate
? new State(contextXstate.value, contextXstate.historyValue)
: machine.initialState;
const event = await mapContextToXStateEvent(context);
const event = await mapContextToXstateEvent(context);

if (onEvent) {
onEvent(event, context);
Expand Down Expand Up @@ -49,4 +49,4 @@ function bottenderXState({
};
}

module.exports = bottenderXState;
module.exports = bottenderXstate;

0 comments on commit f6b3bcd

Please sign in to comment.