Skip to content

Commit 16494fb

Browse files
Merge pull request #355 from LevelbossMike/MIKE/remove-addon-docs
Use docfy - no more addon-docs.
2 parents 262cf50 + eb0ae43 commit 16494fb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+4542
-3884
lines changed

.docfy-config.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const autolinkHeadings = require('remark-autolink-headings');
2+
const docfyWithProse = require('@docfy/plugin-with-prose');
3+
const prism = require('@mapbox/rehype-prism');
4+
const refractor = require('refractor');
5+
6+
refractor.alias('handlebars', 'hbs');
7+
refractor.alias('shell', 'sh');
8+
9+
module.exports = {
10+
tocMaxDepth: 3,
11+
remarkPlugins: [
12+
[
13+
autolinkHeadings,
14+
{
15+
behavior: 'wrap',
16+
},
17+
],
18+
],
19+
plugins: [docfyWithProse],
20+
rehypePlugins: [prism],
21+
labels: {
22+
components: 'Components',
23+
workflow: 'Workflow',
24+
docs: 'Documentation',
25+
},
26+
};

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@
1919
/.node_modules.ember-try/
2020
/bower.json.ember-try
2121
/package.json.ember-try
22+
23+
# api-docs
24+
/tests/dummy/public/api-docs/

.eslintrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ module.exports = {
3838
'.eslintrc.js',
3939
'.prettierrc.js',
4040
'.template-lintrc.js',
41+
'.docfy-config.js',
42+
'tailwind.config.js',
4143
'ember-cli-build.js',
4244
'index.js',
4345
'testem.js',
@@ -60,6 +62,10 @@ module.exports = {
6062
},
6163
plugins: ['node'],
6264
extends: ['plugin:node/recommended'],
65+
rules: {
66+
'node/no-unpublished-require': 'off',
67+
'node/no-extraneous-require': 'off',
68+
},
6369
},
6470
],
6571
};

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@
2020
/testem.log
2121
/yarn-error.log
2222

23+
# generated api-docs
24+
/tests/dummy/public/api-docs/
25+
2326
# ember-try
2427
/.node_modules.ember-try/
2528
/bower.json.ember-try
2629
/package.json.ember-try
30+
31+
.DS_Store

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ language: node_js
33
node_js:
44
# we recommend testing addons with the same minimum supported node version as Ember CLI
55
# so that your addon works for all apps
6-
- "10"
6+
- "14"
77

88
dist: xenial
99

addon/index.ts

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,45 @@ import {
1111
Typestate,
1212
} from 'xstate';
1313

14+
/**
15+
* A decorator that can be used to create a getter that matches against an
16+
* {@link InterpreterUsable}'s state and will return either `true` or `false`
17+
*
18+
*
19+
* ```js
20+
* import Component from '@glimmer/component';
21+
* import buttonMachine from '../machines/button';
22+
*
23+
* export default class Button extends Component {
24+
* @use statechart = useMachine(buttonMachine)
25+
*
26+
* @matchesState('disabled')
27+
* isDisabled; // true when statechart is in `disabled` state
28+
*
29+
* @matchesState({ interactivity: 'disabled' })
30+
* isDisabled; // it is possible to match against nested/parallel states
31+
* }
32+
* ```
33+
*
34+
* You can match against any XState [StateValue](https://xstate.js.org/api/globals.html#statevalue)
35+
*
36+
* By default `matchesState` expects your {@link InterpreterUsable} to be called `statechart`.
37+
* If you named it differently you can use the second param to this decorator:
38+
*
39+
*
40+
* ```js
41+
* import Component from '@glimmer/component';
42+
* import buttonMachine from '../machines/button';
43+
*
44+
* export default class Button extends Component {
45+
* @use sc = useMachine(buttonMachine)
46+
*
47+
* @matchesState('disabled', 'sc')
48+
* isDisabled;
49+
* }
50+
* ```
51+
*
52+
*/
1453
/* eslint-disable @typescript-eslint/no-explicit-any */
1554
function matchesState(
1655
state: StateValue,
@@ -35,7 +74,16 @@ function matchesState(
3574

3675
/**
3776
* No-op typecast function that turns what TypeScript believes to be a
38-
* ConfigurableMachineDefinition function into a InterpreterUsable.
77+
* {@link ConfigurableMachineDefinition} into an {@link InterpreterUsable}.
78+
*
79+
* TypeScript can't deal with decorators changing types thus we need this
80+
* typecasting function because `@use`- will take what `useMachine`
81+
* returns and initialize the actual usable which is the thing that you will
82+
* work with from your code after accessing the usable's value.
83+
*
84+
* This function can be used in two ways:
85+
*
86+
* 1) Whenever you want to send an event to a statechart:
3987
*
4088
* ```js
4189
* import { useMachine, interpreterFor } from 'ember-statecharts';
@@ -52,10 +100,22 @@ function matchesState(
52100
* }
53101
* ```
54102
*
55-
* @param configurableMachineDefinition The ConfigurableMachineDefinition used
56-
* to initialize the `useMachine`-usable via `@use`
103+
* 2) By wrapping `useMachine` directly. This way you don't have to litter the
104+
* rest of your code with `interpreterFor`:
105+
*
106+
* ```js
107+
* import { useMachine, interpreterFor } from 'ember-statecharts';
108+
*
109+
* class Foo extends EmberObject {
110+
* @use statechart = interpreterFor(useMachine(...) {
111+
* // ...
112+
* })
57113
*
58-
* Note that this is purely a typecast function.
114+
* someMethod() {
115+
* this.statechart.send('WAT'); // ok!
116+
* }
117+
* }
118+
* ```
59119
*/
60120
function interpreterFor<
61121
TContext,

addon/usables/use-machine.ts

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ export type UsableStatechart<
5858
| MachineConfig<TContext, TStateSchema, TEvent>
5959
| StateMachine<TContext, TStateSchema, TEvent, TTypestate>;
6060

61+
/**
62+
* An object that makes an XState-[Interpreter](https://xstate.js.org/docs/guides/interpretation.html)
63+
* accessible to the outside world and allows `send`ing events to it.
64+
*
65+
* This is actually the return value of {@link InterpreterService.state}.
66+
*/
6167
export type InterpreterUsable<
6268
TContext,
6369
TStateSchema extends StateSchema,
@@ -134,6 +140,13 @@ export type UseMachineBucket<
134140
};
135141
};
136142

143+
/**
144+
* The actual usable that gets started when a {@link ConfigurableMachineDefinition} is `@use`d.
145+
*
146+
* On initial access this class will setup an XState-[Interpreter](https://xstate.js.org/docs/guides/interpretation.html)
147+
* and make its state available to the outside world.
148+
*
149+
*/
137150
export class InterpreterService<
138151
TContext,
139152
TStateSchema extends StateSchema,
@@ -159,6 +172,25 @@ export class InterpreterService<
159172
this.onTransition = onTransition;
160173
}
161174

175+
/**
176+
* The object that gets returned when you access the Usable.
177+
*
178+
* ```js
179+
* import Component from '@glimmer/component';
180+
* import buttonMachine from '../machines/button';
181+
*
182+
* export default ButtonComponent extends Component {
183+
* @use statechart = useMachine(buttonMachine)
184+
*
185+
* @action
186+
* buttonClicked() {
187+
* // acessing `statechart` will return the return value of this getter
188+
* this.statechart.send('CLICK');
189+
* }
190+
* }
191+
*
192+
* ```
193+
*/
162194
get state(): {
163195
state: State<TContext, TEvent, TStateSchema, TTypestate>;
164196
send: Send<TContext, TStateSchema, TEvent, TTypestate>;
@@ -323,6 +355,81 @@ const createMachineInterpreterManager = () => {
323355
const MANAGED_INTERPRETER = {};
324356
setUsableManager(MANAGED_INTERPRETER, createMachineInterpreterManager);
325357

358+
/**
359+
* A function that lets you define a {@link ConfigurableMachineDefinition} that can be
360+
* `@use`d.
361+
*
362+
*
363+
* ```ts
364+
* import Component from '@glimmer/component';
365+
* import buttonMachine from '../machines/button';
366+
*
367+
* export default ButtonComponent extends Component {
368+
* @use statechart = useMachine(buttonMachine)
369+
*
370+
* @action
371+
* buttonClicked() {
372+
* this.statechart.send('CLICK');
373+
* }
374+
* }
375+
* ```
376+
*
377+
* The {@link ConfigurableMachineDefinition} can be used to override properties
378+
* of the {@link UsableStatechart} that was passed to `useMachine`.
379+
*
380+
* ```ts
381+
* import Component from '@glimmer/component';
382+
* import formMachine from '../machines/form';
383+
* // ...
384+
*
385+
* export default FormComponent extends Component {
386+
* // ...
387+
* @use statechart = useMachine(formMachine)
388+
* .withContext({
389+
* // we can override the machine's context here
390+
* formObject: this.formObject
391+
* })
392+
* .withConfig({
393+
* services: {
394+
* // to override an async function that can be invoked
395+
* submitForm: this.submitForm
396+
* },
397+
* actions: {
398+
* notifyFormSubmission: this.notifyFormSubmission
399+
* },
400+
* guards: {
401+
* // ...
402+
* }
403+
* })
404+
* .onTransition((state) => {
405+
* // when you want to react to transitions manually
406+
* })
407+
* .update(({ send }) => {
408+
* // decide how to handle properties passed to `useMachine` changing
409+
* send('MY_EVENT_TO_HANDLE_ARGS_CHANGES');
410+
* })
411+
*
412+
* @action
413+
* submitForm(context, event) {
414+
* return this.onSubmitForm(context.formObject);
415+
* }
416+
*
417+
* @action
418+
* notifyFormSubmission() {
419+
* this.notifications.notify('Form was submitted');
420+
* }
421+
* }
422+
* ```
423+
*
424+
* A {@link ConfigurableMachineDefinition} is only used to configure how the
425+
* interpreted {@link UsableStatechart} will behave when interacting with it.
426+
*
427+
* When accessing the `@use`d value you are actually dealing with a {@link
428+
* InterpreterUsable} - i.e. an object that gives you access to the
429+
* `state`-property of an XState-[Interpreter](https://xstate.js.org/docs/guides/interpretation.html)
430+
* and a `send`-function that can be used to send events to the interpreter.
431+
*
432+
*/
326433
export default function useMachine<
327434
TContext,
328435
TStateSchema extends StateSchema,

config/addon-docs.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

config/deploy.js

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,12 @@
11
/* eslint-env node */
22
'use strict';
33

4-
module.exports = function (deployTarget) {
4+
module.exports = function (/* deployTarget */) {
55
let ENV = {
66
build: {},
7-
// include other plugin configuration that applies to all deploy targets here
7+
git: {
8+
commitMessage: 'chore: deploy %@',
9+
},
810
};
9-
10-
if (deployTarget === 'development') {
11-
ENV.build.environment = 'development';
12-
// configure other plugins for development deploy target here
13-
}
14-
15-
if (deployTarget === 'staging') {
16-
ENV.build.environment = 'production';
17-
// configure other plugins for staging deploy target here
18-
}
19-
20-
if (deployTarget === 'production') {
21-
ENV.build.environment = 'production';
22-
// configure other plugins for production deploy target here
23-
}
24-
25-
// Note: if you need to build some configuration asynchronously, you can return
26-
// a promise that resolves with the ENV object instead of returning the
27-
// ENV object synchronously.
2811
return ENV;
2912
};

0 commit comments

Comments
 (0)