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

refactor: Sparkles -> Octane #38

Merged
merged 8 commits into from
Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 8 additions & 4 deletions .ember-cli → .ember-cli.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
{
'use strict';

process.env.EMBER_VERSION = 'OCTANE';

module.exports = {
/**
Ember CLI sends analytics information by default. The data is completely
anonymous, but there are times when you might want to disable this behavior.

Setting `disableAnalytics` to true will prevent any data from being sent.
*/
"disableAnalytics": false,
disableAnalytics: false,

"usePods": true
}
usePods: true
};
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try

# broken parser
/types/
11 changes: 7 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ language: node_js
node_js:
# we recommend testing addons with the same minimum supported node version as Ember CLI
# so that your addon works for all apps
- "6"
- "8"

sudo: false
dist: trusty
Expand All @@ -28,7 +28,10 @@ branches:
jobs:
fail_fast: true
allow_failures:
- env: EMBER_TRY_SCENARIO=ember-canary
- env: EMBER_TRY_SCENARIO=ember-lts-3.4
- env: EMBER_TRY_SCENARIO=ember-release
- env: EMBER_TRY_SCENARIO=ember-beta
- env: EMBER_TRY_SCENARIO=ember-default

include:
# runs linting and tests with current locked deps
Expand All @@ -40,7 +43,7 @@ jobs:
script:
- yarn lint:hbs
- yarn lint:js
#- yarn lint:types
- yarn lint:types
- yarn test

- name: "Floating Dependencies"
Expand All @@ -54,7 +57,7 @@ jobs:
- env: EMBER_TRY_SCENARIO=ember-release
- env: EMBER_TRY_SCENARIO=ember-beta
- env: EMBER_TRY_SCENARIO=ember-canary
- env: EMBER_TRY_SCENARIO=ember-default-with-jquery
- env: EMBER_TRY_SCENARIO=ember-default

before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash
Expand Down
15 changes: 4 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ components.
ember install ember-link
```

This addon uses the [`RouterService`][router-service]. Depending on your Ember version, you might
need to install
[`ember-router-service-polyfill`][ember-router-service-polyfill].
> 👉 This is an [Ember Octane][octane] addon. For a version that is compatible
> with older versions of Ember check out the [`0.x` series][pre-octane].

[router-service]: https://api.emberjs.com/ember/release/classes/RouterService
[ember-router-service-polyfill]: https://github.com/rwjblue/ember-router-service-polyfill#readme
[octane]: https://emberjs.com/editions/octane/
[pre-octane]: https://github.com/buschtoens/ember-link/tree/pre-octane

## Usage

Expand All @@ -48,12 +47,6 @@ as |l|>
</Link>
```

<sup>`{{on}}` is an element modifier provided by
[`ember-on-modifier`][ember-on-modifier]. You could just use
`onclick={{l.transitionTo}}` instead.</sup>

[ember-on-modifier]: https://github.com/buschtoens/ember-on-modifier#readme

### Arguments

#### `@route`
Expand Down
47 changes: 11 additions & 36 deletions addon/components/link/component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import RouterService from '@ember/routing/router-service';
import Transition from '@ember/routing/-private/transition';
import { inject as service } from '@ember-decorators/service';
import { action } from '@ember-decorators/object';
import { reads } from '@ember-decorators/object/computed';
import SparklesComponent, { tracked } from 'sparkles-component';
import { assert } from '@ember/debug';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { reads } from '@ember/object/computed';
import Component from '@glimmer/component';

function isQueryParams(
maybeQueryParam: any
Expand All @@ -20,7 +19,7 @@ type RouteModel = object | string | number;

type QueryParams = Record<string, any>;

export default class LinkComponent extends SparklesComponent<{
export interface LinkArgs {
/**
* The target route name.
*/
Expand Down Expand Up @@ -50,38 +49,16 @@ export default class LinkComponent extends SparklesComponent<{
* Defaults to `true`.
*/
preventDefault?: boolean;
}> {
}

export default class LinkComponent extends Component<LinkArgs> {
@service
private router!: RouterService;

@reads('router.currentURL')
// @ts-ignore
private currentURL!: string;

didUpdate() {
super.didUpdate();

assert(
`You provided '@queryParams', but the argument you mean is just '@query'.`,
!('queryParams' in this.args)
);
assert(
`You provided '@routeName', but the argument you mean is just '@route'.`,
!('routeName' in this.args)
);
assert(
`'@route' needs to be a valid route name.`,
typeof this.args.route === 'string'
);
assert(
`You cannot use both '@model' ('${this.args.model}') and '@models' ('${
this.args.models
}') at the same time.`,
!(this.args.model && this.args.models)
);
}

@tracked('args')
private get modelsAndQueryParams(): [RouteModel[], null | QueryParams] {
const { model, models, query } = this.args;
if (models) {
Expand All @@ -100,7 +77,6 @@ export default class LinkComponent extends SparklesComponent<{
return [model ? [model] : [], query ? { ...query } : null];
}

@tracked
private get routeArgs() {
const [models, queryParams] = this.modelsAndQueryParams;

Expand All @@ -115,7 +91,6 @@ export default class LinkComponent extends SparklesComponent<{
* The URL for this link that you can pass to an `<a>` tag as the `href`
* attribute.
*/
@tracked('args')
get href(): string {
// @ts-ignore
return this.router.urlFor(...this.routeArgs);
Expand All @@ -125,8 +100,8 @@ export default class LinkComponent extends SparklesComponent<{
* Whether this route is currently active, including potentially supplied
* models and query params.
*/
@tracked('args', 'currentURL')
get isActive(): boolean {
this.currentURL; // eslint-disable-line no-unused-expressions
// @ts-ignore
return this.router.isActive(...this.routeArgs);
}
Expand All @@ -135,8 +110,8 @@ export default class LinkComponent extends SparklesComponent<{
* Whether this route is currently active, including potentially supplied
* models, but ignoring query params.
*/
@tracked('args', 'currentURL')
get isActiveWithoutQueryParams() {
this.currentURL; // eslint-disable-line no-unused-expressions
return this.router.isActive(
this.args.route,
// @ts-ignore
Expand All @@ -148,8 +123,8 @@ export default class LinkComponent extends SparklesComponent<{
* Whether this route is currently active, but ignoring models and query
* params.
*/
@tracked('args', 'currentURL')
get isActiveWithoutModels() {
this.currentURL; // eslint-disable-line no-unused-expressions
return this.router.isActive(this.args.route);
}

Expand Down
6 changes: 4 additions & 2 deletions addon/components/link/template.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{{yield
{{~ember-link/validate-args this.args~}}

{{~yield
(hash
href=this.href
isActive=this.isActive
Expand All @@ -7,4 +9,4 @@
transitionTo=this.transitionTo
replaceWith=this.replaceWith
)
}}
~}}
26 changes: 26 additions & 0 deletions addon/helpers/ember-link/validate-args.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { helper } from '@ember/component/helper';
import { assert } from '@ember/debug';
import { LinkArgs } from 'ember-link/components/link/component';

export function emberLinkValidateArgs([args]: [LinkArgs]): void {
assert(
`You provided '@queryParams', but the argument you mean is just '@query'.`,
!('queryParams' in args)
);
assert(
`You provided '@routeName', but the argument you mean is just '@route'.`,
!('routeName' in args)
);
assert(
`'@route' needs to be a valid route name.`,
typeof args.route === 'string'
);
assert(
`You cannot use both '@model' ('${args.model}') and '@models' ('${
args.models
}') at the same time.`,
!(args.model && args.models)
);
}

export default helper(emberLinkValidateArgs);
Empty file added addon/index.js
Empty file.
4 changes: 4 additions & 0 deletions app/helpers/ember-link/validate-args.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export {
default,
emberLinkValidateArgs
} from 'ember-link/helpers/ember-link/validate-args';
25 changes: 8 additions & 17 deletions config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ module.exports = function() {
return {
useYarn: true,
scenarios: [
{
name: 'ember-lts-2.18',
npm: {
devDependencies: {
'ember-source': '~2.18.0'
}
}
},
{
name: 'ember-lts-3.4',
npm: {
Expand Down Expand Up @@ -43,28 +51,11 @@ module.exports = function() {
}
}
},
// The default `.travis.yml` runs this scenario via `yarn test`,
// not via `ember try`. It's still included here so that running
// `ember try:each` manually or from a customized CI config will run it
// along with all the other scenarios.
{
name: 'ember-default',
npm: {
devDependencies: {}
}
},
{
name: 'ember-default-with-jquery',
env: {
EMBER_OPTIONAL_FEATURES: JSON.stringify({
'jquery-integration': true
})
},
npm: {
devDependencies: {
'@ember/jquery': '^0.5.1'
}
}
}
]
};
Expand Down
6 changes: 6 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"experimentalDecorators": true
},
"exclude": ["node_modules", "dist"]
}
21 changes: 9 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,16 @@
"postpublish": "#ember ts:clean"
},
"dependencies": {
"@ember-decorators/babel-transforms": "^5.1.4",
"@ember-decorators/object": "^5.1.4",
"@ember-decorators/service": "^5.1.4",
"ember-cli-babel": "^7.7.3",
"ember-cli-htmlbars": "^3.0.1",
"ember-cli-typescript": "^2.0.0",
"sparkles-component": "^1.3.0"
"ember-cli-typescript": "^2.0.1"
},
"devDependencies": {
"@clark/eslint-config-ember": "^0.5.1",
"@clark/eslint-config-ember-typescript": "^0.5.1",
"@clark/eslint-config-node": "^0.5.0",
"@ember/optional-features": "^0.7.0",
"@glimmer/component": "^0.14.0-alpha.4",
"@types/ember": "^3.1.0",
"@types/ember-qunit": "^3.4.6",
"@types/ember-test-helpers": "^1.0.5",
Expand All @@ -45,34 +42,34 @@
"@types/qunit": "^2.5.4",
"@types/rsvp": "^4.0.2",
"broccoli-asset-rev": "^3.0.0",
"ember-cli": "~3.8.1",
"ember-cli": "github:ember-cli/ember-cli#7d9fce01d8faa4ce69cc6a8aab6f7f07b6b88425",
"ember-cli-dependency-checker": "^3.1.0",
"ember-cli-htmlbars-inline-precompile": "^2.1.0",
"ember-cli-inject-live-reload": "^2.0.1",
"ember-cli-sri": "^2.1.1",
"ember-cli-typescript-blueprints": "^2.0.0",
"ember-cli-uglify": "^2.1.0",
"ember-cli-uglify": "^3.0.0",
"ember-disable-prototype-extensions": "^1.1.3",
"ember-export-application-global": "^2.0.0",
"ember-load-initializers": "^2.0.0",
"ember-maybe-import-regenerator": "^0.1.6",
"ember-on-modifier": "^0.8.0",
"ember-on-modifier": "^0.12.1",
"ember-qunit": "^4.4.1",
"ember-resolver": "^5.0.1",
"ember-source": "~3.9.0",
"ember-source": "https://s3.amazonaws.com/builds.emberjs.com/canary/shas/c8f479e7951c6888e70d7e7849668c9efe169611.tgz",
"ember-source-channel-url": "^1.1.0",
"ember-template-lint": "^1.1.0",
"ember-try": "^1.0.0",
"eslint": "^5.16.0",
"loader.js": "^4.7.0",
"qunit-dom": "^0.8.4",
"typescript": "^3.4.1"
"qunit-dom": "^0.8.5",
"typescript": "^3.4.5"
},
"resolutions": {
"handlebars": "~4.0.13"
},
"engines": {
"node": "6.* || 8.* || >= 10.*"
"node": "8.* || >= 10.*"
},
"ember-addon": {
"configPath": "tests/dummy/config"
Expand Down
2 changes: 1 addition & 1 deletion tests/dummy/app/helpers/array.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { helper } from '@ember/component/helper';

// Not natively available in Ember 3.4 and below
export function array(params) {
export function array(params: any[]) {
return params;
}

Expand Down
7 changes: 5 additions & 2 deletions tests/dummy/config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ module.exports = function(environment) {
locationType: 'auto',
EmberENV: {
FEATURES: {
// Here you can enable experimental features on an ember canary build
// e.g. 'with-controller': true
EMBER_NATIVE_DECORATOR_SUPPORT: true,
EMBER_METAL_TRACKED_PROPERTIES: true,
EMBER_GLIMMER_ANGLE_BRACKET_NESTED_LOOKUP: true,
EMBER_GLIMMER_ANGLE_BRACKET_BUILT_INS: true,
EMBER_GLIMMER_FN_HELPER: true
},
EXTEND_PROTOTYPES: {
// Prevent Ember Data from overriding Date.parse.
Expand Down
Loading