Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Octane and much polish and clarification #935

Merged
merged 131 commits into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
0978813
docs: begin work on Octane docs push
chriskrycho Nov 6, 2019
d5bf2e2
docs: add constructor to simplified Component definition
chriskrycho Nov 6, 2019
6bd300a
docs: clarify `this.args` in Glimmer component docs
chriskrycho Nov 6, 2019
6c1f58f
docs: make some small improvements to Glimmer Component page
chriskrycho Nov 9, 2019
5b4d971
docs: start the Legacy Ember Components page
chriskrycho Nov 9, 2019
c1fc7a7
docs: fix a typo in Glimmer docs
chriskrycho Nov 9, 2019
d19c2cb
docs: begin work on testing page
chriskrycho Nov 22, 2019
b65a980
docs: add more material about tests
chriskrycho Nov 22, 2019
0204699
docs: auto deploy draft Octane docs
dfreeman Nov 22, 2019
937b014
docs: set explicit version path in docs deploy
dfreeman Nov 23, 2019
55289b5
docs: add new outline structure
chriskrycho Dec 5, 2019
d1b6e33
docs: remove duplicate docs
chriskrycho Dec 5, 2019
993acbb
docs: rename 'Setup' to 'Getting Started'
chriskrycho Dec 7, 2019
e79d768
docs: tweak invocation of DocsViewer in docs template
chriskrycho Dec 7, 2019
69bbb21
docs: drop unneeded root guide template
chriskrycho Dec 7, 2019
b9082c6
docs: put general disclaimer in index
chriskrycho Dec 7, 2019
f9d4c41
docs: header for Apps and Addons page
chriskrycho Dec 7, 2019
8b17cc6
docs: improve text of Legacy Overview
chriskrycho Dec 7, 2019
b54ff71
docs: improve text and fix headings of Testing guide
chriskrycho Dec 7, 2019
0fbadb8
docs: use DocViewer in components guide
chriskrycho Dec 7, 2019
698491b
docs: fix bad link-to invocation
chriskrycho Dec 7, 2019
ccd00ef
docs: add Getting Started root page template
chriskrycho Dec 7, 2019
52d0ad1
docs: add root Getting Started template
chriskrycho Dec 7, 2019
b9f3c7b
docs: drop Getting Started template, change links
chriskrycho Dec 7, 2019
701d763
Merge branch 'master' into octane-docs
jamescdavis Dec 7, 2019
a248694
Merge branch 'master' into octane-docs
chriskrycho Dec 9, 2019
42fe756
docs: clarify `...arguments` unsafety
chriskrycho Dec 9, 2019
b7e4e99
docs: elaborate on `super` and `this`
chriskrycho Dec 9, 2019
14d031e
docs: use demo and snippet for Component docs
chriskrycho Dec 9, 2019
ed3970b
docs: continue building out component guide
chriskrycho Dec 9, 2019
000184d
docs: begin filling out Helper guide
chriskrycho Dec 19, 2019
b6c8cd4
chore(deps): merge latest changes from master
chriskrycho Dec 19, 2019
5847eea
docs: fix demo example in helpers guide
chriskrycho Dec 19, 2019
568e17f
docs: iterate on component examples
chriskrycho Dec 22, 2019
e91e2c0
chore(deps): update dependency ember-cli-addon-docs to v0.6.16
jamescdavis Jan 18, 2020
65164e6
chore(deps): upgrade dependency ember-cli-addon-docs to b180220
jamescdavis Jan 18, 2020
0f4f9fb
docs: improve helper examples
chriskrycho Jan 20, 2020
5766e28
docs: clarify example in helper docs
chriskrycho Jan 20, 2020
2325dee
docs: simplify functional helper type
chriskrycho Jan 20, 2020
3b29e4f
docs: restructure to support Ember Data
chriskrycho Jan 20, 2020
9149904
docs: include prettier fixes from master
chriskrycho Jan 20, 2020
6f247a6
docs: basic overview text for Ember section
chriskrycho Jan 20, 2020
169935f
docs: rename and restructure TS route section
chriskrycho Jan 20, 2020
b029a86
docs: fix Ember guide references to match 3b29e4f
chriskrycho Jan 20, 2020
59b7861
docs: add content and another stub for Ember Data
chriskrycho Jan 20, 2020
bd8ee91
docs: make overview reflect new structure
chriskrycho Jan 20, 2020
d4041b5
docs: fill out `@attr` guide
chriskrycho Jan 20, 2020
9e03eee
docs: add an intro to Model guide
chriskrycho Jan 20, 2020
7e03549
docs: explain `@belongsTo` usage and caveats
chriskrycho Jan 20, 2020
43ed5e8
docs: explain Promise(Object|ManyArray) imports
chriskrycho Jan 20, 2020
2b909d5
docs: explain `@hasMany` usage and caveats
chriskrycho Jan 20, 2020
0bf5b58
docs: extract has-many and belongs-to to snippets
chriskrycho Jan 20, 2020
bfeda3c
docs: exclude snippets from type-checking
chriskrycho Jan 20, 2020
5acf6c1
docs: add Services guide
jamescdavis Jan 22, 2020
356fc31
docs: note our inclusion of blueprints
chriskrycho Jan 22, 2020
09edd28
docs: improve main overview outline
chriskrycho Jan 22, 2020
601f0cb
docs: extract CP `this` discussion to own page
chriskrycho Jan 23, 2020
0ca18d9
docs: add snippet files for services guide
jamescdavis Jan 23, 2020
67fa036
docs: actually include CP guide
chriskrycho Jan 24, 2020
5161e81
docs: add a cookbook section and one "recipe"
chriskrycho Jan 24, 2020
f010a3c
docs: add non-null assertion to service injections
jamescdavis Jan 28, 2020
7165edf
docs: add explanation of needing non-null assertion for service injec…
jamescdavis Jan 29, 2020
3fcf219
docs: better formatting for bad service usage comment
jamescdavis Jan 29, 2020
657f25c
docs: add caution about type-casting service lookups
jamescdavis Jan 29, 2020
09314f8
Merge remote-tracking branch 'origin/master' into octane-docs
chriskrycho Nov 23, 2020
bf86338
chore(deps): update deps after merge
chriskrycho Nov 23, 2020
fe4e72e
docs: recommend `declare` instead of definite-initialization
chriskrycho Nov 23, 2020
8b7f386
chore(ci): use Node 10 for Docs publishing
chriskrycho Nov 23, 2020
d9ad89e
docs: recommend TrackedArray over EmberArray
chriskrycho Nov 23, 2020
2df9346
docs: update note on service lookup cast
chriskrycho Nov 23, 2020
891f258
docs: explain `declare` instead of definite initialization
chriskrycho Nov 23, 2020
108c561
docs: describe use of `declare` instead of `!`
chriskrycho Nov 23, 2020
38188ad
docs: further `!` -> `declare` improvements
chriskrycho Nov 23, 2020
292765c
docs: clarify issues, solutions in conflicting-types
chriskrycho Nov 23, 2020
d641e26
docs: fix Ember Data imports and remove outdated blog links
chriskrycho Nov 23, 2020
7f57d0a
docs: fix more Ember Data references
chriskrycho Nov 23, 2020
a0116b6
docs: remove reference to ember-browserify
chriskrycho Nov 23, 2020
c89eb3c
docs: routing
chriskrycho Nov 23, 2020
25bc558
docs: controllers
chriskrycho Nov 23, 2020
e704980
docs: clarify that `noEmitOnError: true` fails your build
chriskrycho Nov 23, 2020
92a0bd5
docs: remove pages for adapters, serializers, and transforms
chriskrycho Nov 23, 2020
0d24bc8
docs: on legacy computed properties
chriskrycho Nov 23, 2020
7da5e0e
docs: mixins -- mostly for how to migrate away!
chriskrycho Nov 23, 2020
dfc410b
docs: remove page on EmberComponent
chriskrycho Nov 23, 2020
745ae42
docs: on generics in subclasses
chriskrycho Nov 23, 2020
b46c16c
docs: fix a TODO link
chriskrycho Nov 23, 2020
482b727
docs: fix remaining TODOs in helper docs
chriskrycho Nov 23, 2020
2811d5b
docs: fix TODO links in helpers docs
chriskrycho Nov 23, 2020
99bd07e
docs: fix TODOs in testing guide
chriskrycho Nov 23, 2020
79fc492
docs: fix a TODO in overview
chriskrycho Nov 23, 2020
dae619f
docs: improve legacy guide
chriskrycho Nov 23, 2020
7758f88
docs: begin reworking into a Gitbook repo
chriskrycho Nov 24, 2020
d68b24b
chore(docs): configuring GitBook
chriskrycho Nov 24, 2020
4176b19
docs: replace a docs snippet with inlined example
chriskrycho Nov 24, 2020
de57fb4
docs: gitbook-ready components page
chriskrycho Nov 24, 2020
29f6414
docs: simplify installation writeup
chriskrycho Nov 24, 2020
0203bac
docs: further de-addon-docs-ing of component guide
chriskrycho Nov 24, 2020
006c144
docs: drop inlined snippet
chriskrycho Nov 24, 2020
f618237
docs: de-addon-docs-ify helpers guide
chriskrycho Nov 24, 2020
c864adc
docs: de-addon-docs-ify services guide
chriskrycho Nov 24, 2020
3d6e42c
docs: elaborate tracked-built-ins rec
chriskrycho Nov 24, 2020
51ec9ac
docs: drop pages for adapters, serializers, transforms
chriskrycho Nov 24, 2020
78d169a
docs: de-addon-docs-ify Ember Data Model guide
chriskrycho Nov 24, 2020
3ca1974
docs: de-addon-docs-ify working-with-route-models
chriskrycho Nov 24, 2020
049b095
docs: drop now-unused snippets
chriskrycho Nov 24, 2020
5543bba
docs: remove addon-docs from dummy app router
chriskrycho Nov 24, 2020
8130565
docs: clean up other addon-docs implementation
chriskrycho Nov 24, 2020
1622992
docs: drop now-unneeded docs action
chriskrycho Nov 24, 2020
adb53ab
docs: replace asides with hints or warnings
chriskrycho Nov 24, 2020
3a434de
docs: fix gitbook config for summary
chriskrycho Nov 24, 2020
e55338e
docs: update from GitBook -- 37 pages modified
chriskrycho Nov 24, 2020
4f1aa36
docs: remove now-unnecessary ember-cli-deploy
chriskrycho Nov 24, 2020
9a6c2c1
docs: restructure and use Gitbook style
chriskrycho Nov 24, 2020
3734a03
docs: fix links for installation and configuration
chriskrycho Nov 24, 2020
7a43168
docs: fix capitalization of Cookbook
chriskrycho Nov 24, 2020
91f1556
docs: fix another link
chriskrycho Nov 24, 2020
ee8fae9
docs: internal linking and organization
chriskrycho Nov 24, 2020
3d80a5f
docs: further improve outline
chriskrycho Nov 24, 2020
3cd77bb
docs: include index in outline
chriskrycho Nov 24, 2020
496fa76
docs: remove needless references to ember-decorators
chriskrycho Nov 24, 2020
4dcb2de
docs: tweak grammar on landing page
chriskrycho Nov 24, 2020
edafc5f
docs: remove content from using-ts-effectively
chriskrycho Nov 24, 2020
30eb350
docs: improve Decorators page content
chriskrycho Nov 24, 2020
0f9f088
docs: clarify/correct language around Babel config
chriskrycho Nov 24, 2020
1a593e8
docs: add outline to Working With Ember page
chriskrycho Nov 24, 2020
f35db2b
docs: improve installation writuep
chriskrycho Nov 24, 2020
83724cf
docs: fix links in primary overview
chriskrycho Nov 24, 2020
66256f1
docs: improve Using TS With Ember Effectively
chriskrycho Nov 24, 2020
979f16d
docs: eliminate needless escaping of parentheses
chriskrycho Nov 24, 2020
6d0f586
Merge branch 'master' into octane-docs
chriskrycho Dec 21, 2020
7d6628a
chore: fix accidentally misconfigured lint setting
chriskrycho Dec 22, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ module.exports = {
ecmaVersion: 2017,
sourceType: 'module',
},
plugins: ['ember', '@typescript-eslint', 'prettier'],
extends: ['eslint:recommended', 'plugin:ember/recommended'],
plugins: ['ember', '@typescript-eslint'],
extends: ['eslint:recommended', 'plugin:ember/recommended', 'prettier/@typescript-eslint'],
env: {
browser: true,
},
rules: {
"prettier/prettier": "error"
'prettier/prettier': 'error',
},
settings: {
node: {
Expand Down Expand Up @@ -43,14 +43,10 @@ module.exports = {
node: true,
},
plugins: ['node'],
rules: Object.assign(
{},
require('eslint-plugin-node').configs.recommended.rules,
{
// add your custom rules and overrides for node files here
'ember/avoid-leaking-state-in-ember-objects': 'off',
}
),
rules: Object.assign({}, require('eslint-plugin-node').configs.recommended.rules, {
// add your custom rules and overrides for node files here
'ember/avoid-leaking-state-in-ember-objects': 'off',
}),
},

// test files
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/octane-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Publish Draft Octane Docs

on:
push:
branches:
- octane-docs

jobs:
deploy-docs:
name: Deploy Docs Preview
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v1
- name: Install Node
uses: actions/setup-node@v1
with:
node-version: '^8.12'
- name: Install Dependencies
run: yarn install --frozen-lockfile
- name: Set Git Identity
run: |
git config --global user.name "Tomster"
git config --global user.email "[email protected]"
- name: Publish Docs
run: yarn ember deploy production
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ADDON_DOCS_VERSION_PATH: 'octane-docs'
6 changes: 6 additions & 0 deletions config/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
module.exports = function(deployTarget) {
let ENV = {
build: {},
git: {},
// include other plugin configuration that applies to all deploy targets here
};

Expand All @@ -22,6 +23,11 @@ module.exports = function(deployTarget) {
// configure other plugins for production deploy target here
}

const { GITHUB_ACTOR, GITHUB_TOKEN } = process.env;
if (GITHUB_ACTOR && GITHUB_TOKEN) {
ENV.git.repo = `https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/typed-ember/ember-cli-typescript.git`;
}

// Note: if you need to build some configuration asynchronously, you can return
// a promise that resolves with the ENV object instead of returning the
// ENV object synchronously.
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
"@commitlint/cli": "8.2.0",
"@commitlint/config-conventional": "8.2.0",
"@ember/optional-features": "1.2.0",
"@glimmer/component": "^1.0.0-beta.3",
"@glimmer/tracking": "^1.0.0-beta.3",
"@typed-ember/renovate-config": "1.2.1",
"@types/capture-console": "1.0.0",
"@types/chai": "4.2.7",
Expand All @@ -66,6 +68,7 @@
"@types/debug": "4.1.5",
"@types/ember": "3.1.1",
"@types/ember-qunit": "3.4.7",
"@types/ember__object": "^3.1.1",
"@types/esprima": "4.0.2",
"@types/express": "4.17.1",
"@types/fs-extra": "8.0.1",
Expand All @@ -84,7 +87,7 @@
"commitlint-azure-pipelines-cli": "1.0.2",
"conventional-changelog-cli": "2.0.31",
"ember-cli": "3.14.0",
"ember-cli-addon-docs": "ember-learn/ember-cli-addon-docs#4f5bfd11",
"ember-cli-addon-docs": "ember-learn/ember-cli-addon-docs#b180220",
"ember-cli-addon-docs-esdoc": "0.2.3",
"ember-cli-app-version": "3.2.0",
"ember-cli-babel": "7.13.2",
Expand All @@ -110,6 +113,7 @@
"ember-source": "3.15.0",
"ember-try": "1.4.0",
"eslint": "6.7.2",
"eslint-config-prettier": "^6.9.0",
"eslint-plugin-ember": "7.7.2",
"eslint-plugin-node": "10.0.0",
"eslint-plugin-prettier": "3.1.2",
Expand All @@ -123,6 +127,7 @@
"loader.js": "4.7.0",
"mocha": "6.2.2",
"prettier": "1.18.2",
"prettier-eslint": "^9.0.1",
"qunit-dom": "0.9.2",
"testdouble": "3.12.4",
"tmp": "0.1.0",
Expand Down
9 changes: 9 additions & 0 deletions tests/dummy/app/components/args-getter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// BEGIN-SNIPPET args-getter.ts
import Component from '@glimmer/component';

export default class ArgsDisplay extends Component {
get argNames(): string[] {
return Object.keys(this.args);
}
}
// END-SNIPPET
30 changes: 30 additions & 0 deletions tests/dummy/app/helpers/show-all.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
interface Dict<T = unknown> {
[key: string]: T | undefined;
}

// BEGIN-SNIPPET show-all.ts
import { helper } from '@ember/component/helper';

const describe = (entries: string): string => (entries.length > 0 ? entries : '(none)');

export function showAll(positional: unknown[], named: Dict) {
// pretty print each item with its index, like `0: { neat: true }` or
// `1: undefined`.
const positionalEntries = positional
.reduce<string[]>((items, arg, index) => items.concat(`${index}: ${JSON.stringify(arg)}`), [])
.join(', ');

// pretty print each item with its name, like `cool: beans` or
// `answer: 42`.
const namedEntries = Object.keys(named)
.reduce<string[]>(
(items, key) => items.concat(`${key}: ${JSON.stringify(named[key], undefined, 2)}`),
[]
)
.join(', ');

return `positional: ${describe(positionalEntries)}\nnamed: ${describe(namedEntries)}`;
}

export default helper(showAll);
// END-SNIPPET
4 changes: 4 additions & 0 deletions tests/dummy/app/lib/generate-avatar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** This exists just to support example code. */
export function generateUrl(): string {
return '';
}
41 changes: 38 additions & 3 deletions tests/dummy/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,48 @@ const Router = AddonDocsRouter.extend({

Router.map(function() {
docsRoute(this, function() {
this.route('upgrade-notes');
this.route('configuration');
this.route('ts-guide', function() {
this.route('getting-started', function() {
this.route('installation');
this.route('configuration');
});

this.route('ts', function() {
this.route('overview');
this.route('decorators');
this.route('with-addons');
this.route('using-ts-effectively');
this.route('current-limitations');
});

this.route('ember', function() {
this.route('overview');
this.route('components');
this.route('services');
this.route('testing');
this.route('routes');
this.route('controllers');
this.route('helpers');
this.route('apps-and-addons');
});

this.route('ember-data', function() {
this.route('overview');
this.route('models');
this.route('adapters');
this.route('serializers');
this.route('transforms');
});

this.route('legacy', function() {
this.route('overview');
this.route('ember-object');
this.route('computed-properties');
this.route('mixins');
this.route('ember-component');
});

this.route('upgrade-notes');

this.route('troubleshooting', function() {
this.route('conflicting-types');
});
Expand Down
13 changes: 13 additions & 0 deletions tests/dummy/app/snippets/args-display.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// BEGIN-SNIPPET args-display.ts
import Component from '@glimmer/component';

const log = console.log.bind(console);

export default class ArgsDisplay extends Component {
constructor(owner: unknown, args: {}) {
super(owner, args);

Object.keys(args).forEach(log);
}
}
// END-SNIPPET
14 changes: 14 additions & 0 deletions tests/dummy/app/snippets/belongs-to.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// BEGIN-SNIPPET belongs-to.ts
import Model, { belongsTo } from '@ember-data/model';
import DS from 'ember-data'; // NOTE: this is a workaround, see discussion below!
import User from './user';
import Site from './site';

export default class Post extends Model {
@belongsTo('user')
user!: DS.PromiseObject<User>;

@belongsTo('site', { async: false })
site!: Site;
}
// END-SNIPPET
17 changes: 17 additions & 0 deletions tests/dummy/app/snippets/cart-contents-bad.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// BEGIN-SNIPPET cart-contents-bad.ts
import Component from '@glimmer/component';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';

import ShoppingCartService from 'my-app/services/shopping-cart';

export default class CartContentsComponent extends Component {
@service shoppingCart: ShoppingCartService;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@service shoppingCart: ShoppingCartService;
@service shoppingCart!: ShoppingCartService;


@action
remove(item) {
// Error: Property 'saveForLater' does not exist on type 'ShoppingCartService'.
this.shoppingCart.saveForLater(item);
}
};
// END-SNIPPET
18 changes: 18 additions & 0 deletions tests/dummy/app/snippets/cart-contents-lookup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// BEGIN-SNIPPET cart-contents-lookup.ts
import Component from '@glimmer/component';
import { getOwner } from '@ember/application';
import { action } from '@ember/object';

import ShoppingCartService from 'my-app/services/shopping-cart';

export default class CartContentsComponent extends Component {
get cart() {
return getOwner(this).lookup('service:shopping-cart') as ShoppingCartService;
Copy link
Member Author

@chriskrycho chriskrycho Jan 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mentioned it in the writeup, but let's be extra explicit that this cast is wildly unsafe and the user has to guarantee it. If they typo the lookup, they'll get back null or something else.

It occurs to me that we could improve this by defining an OwnerRegistry and registering things there… but mostly I wish that the lookup API were lookup(bucket, name) instead of lookup('<bucket>:<name>'), because if it were we could trivially reuse the existing registries.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely would be good to be extra explicit here. I was thinking the exact same thing about a registry for this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened an issue on the RFCs repo for that idea, and will hopefully 🤞 write an actual RFC for it if there's interest.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RFC #585 for the above concern!

}

@action
remove(item) {
this.cart.remove(item);
}
};
// END-SNIPPET
16 changes: 16 additions & 0 deletions tests/dummy/app/snippets/cart-contents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// BEGIN-SNIPPET cart-contents.ts
import Component from '@glimmer/component';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';

import ShoppingCartService from 'my-app/services/shopping-cart';

export default class CartContentsComponent extends Component {
@service shoppingCart: ShoppingCartService;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@service shoppingCart: ShoppingCartService;
@service shoppingCart!: ShoppingCartService;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll also explain this.


@action
remove(item) {
this.shoppingCart.remove(item);
}
};
// END-SNIPPET
8 changes: 8 additions & 0 deletions tests/dummy/app/snippets/dict-usage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// BEGIN-SNIPPET dict-usage.ts
let ages: Dict<number> = {
chris: 32,
};

let johnAge = ages['john']; // undefined
let chrisAge = ages['chris']; // 32
// END-SNIPPET
5 changes: 5 additions & 0 deletions tests/dummy/app/snippets/dict.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// BEGIN-SNIPPET dict.ts
interface Dict<T = unknown> {
[key: string]: T | undefined;
}
// END-SNIPPET
28 changes: 28 additions & 0 deletions tests/dummy/app/snippets/function-based-helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
declare module '@ember/debug' {
export function assert(message: string, value: unknown): asserts value;
}

// BEGIN-SNIPPET function-based-helper.ts
import { helper } from '@ember/component/helper';
import { assert } from '@ember/debug';
import { is } from '../../type-utils'

export function join(positional: [unknown, unknown], named: Dict<unknown>) {
assert(
`'join' requires two 'string' positional parameters`,
is<[string, string]>(
positional,
positional.length === 2 &&
positional.every(el => typeof el === 'string')
)
);
assert(`'join' requires argument 'separator'`, typeof named.separator === 'string');

const joined = positional.join(named.separator);
const prefix = typeof named.prefix === 'string' ? named.prefix : '';

return `${prefix}${joined}`;
}

export default helper(join);
// END-SNIPPET
15 changes: 15 additions & 0 deletions tests/dummy/app/snippets/has-many.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// BEGIN-SNIPPET has-many.ts
import Model, { hasMany } from '@ember-data/model';
import EmberArray from '@ember/array';
import DS from 'ember-data'; // NOTE: this is a workaround, see discussion below!
import Comment from './comment';
import User from './user';

export default class Thread extends Model {
@hasMany('comment')
comment!: DS.PromiseManyArray<Comment>;

@hasMany('user', { async: false })
participants!: EmberArray<User>;
}
// END-SNIPPET
20 changes: 20 additions & 0 deletions tests/dummy/app/snippets/shopping-cart.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// BEGIN-SNIPPET shopping-cart.ts
import { A } from '@ember/array';
import Service from '@ember/service';

export default class ShoppingCartService extends Service {
items = A([]);

add(item) {
this.items.pushObject(item);
}

remove(item) {
this.items.removeObject(item);
}

empty() {
this.items.clear();
}
}
// END-SNIPPET
7 changes: 7 additions & 0 deletions tests/dummy/app/snippets/simplified-glimmer-component.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// BEGIN-SNIPPET simplified-glimmer-component.d.ts
export default class Component<Args extends {} = {}> {
args: Args;

constructor(owner: unknown, args: Args);
}
// END-SNIPPET
Loading