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

Upgrade glint #776

Merged
merged 8 commits into from
Mar 3, 2023
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
3 changes: 2 additions & 1 deletion .changeset/curvy-frogs-sin.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
"ember-resources": major
---

Drop support for TypeScript < 4.8
Drop support for TypeScript < 4.8 in order to support Glint.

5 changes: 5 additions & 0 deletions .changeset/twenty-adults-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ember-resources": minor
---

Glint is now supported starting with 1.0.0-beta.3
5 changes: 5 additions & 0 deletions ember-resources/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ module.exports = {
{
files: ['**/*.ts'],
rules: {
/**
* This one is incorrectly parsed for now, because
* the rule doesn't understand decorators
*/
'@typescript-eslint/no-unused-vars': 'off',
/**
* any can be useful
*/
Expand Down
9 changes: 5 additions & 4 deletions ember-resources/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@
"@ember/test-waiters": "^3.0.0",
"@glimmer/component": "^1.1.2",
"@glimmer/tracking": "^1.1.2",
"@glint/template": ">= 0.8.3",
"@glint/template": "^1.0.0-beta.3 || ^1.0.0",
"ember-concurrency": "^2.0.0",
"ember-source": ">= 3.28.0"
"ember-source": "^3.28.0 || ^4.0.0 || ^5.0.0"
},
"peerDependenciesMeta": {
"@glimmer/component": {
Expand All @@ -126,7 +126,7 @@
"@embroider/addon-dev": "^3.0.0",
"@glimmer/component": "^1.1.2",
"@glimmer/tracking": "^1.1.2",
"@glint/template": "^0.8.3",
"@glint/template": "^1.0.0-beta.3",
"@nullvoxpopuli/eslint-configs": "^3.0.0",
"@types/ember__application": "^4.0.0",
"@types/ember__component": "^4.0.8",
Expand All @@ -136,13 +136,14 @@
"@types/ember__object": "^4.0.2",
"@types/ember__owner": "^4.0.0",
"@types/ember__runloop": "^4.0.1",
"@types/ember__test-helpers": "^2.0.0",
"babel-eslint": "10.1.0",
"ember-async-data": "^0.7.0",
"ember-template-lint": "3.16.0",
"ember-source": "4.11.0",
"eslint": "^7.32.0",
"expect-type": "^0.15.0",
"npm-run-all": "4.1.5",
"prettier": "^2.8.4",
"rollup": "3.18.0",
"rollup-plugin-ts": "^3.0.0",
"tslib": "^2.4.0",
Expand Down
53 changes: 48 additions & 5 deletions ember-resources/src/core/function-based/immediate-invocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { associateDestroyableChild } from '@ember/destroyable';
// @ts-ignore
import { capabilities as helperCapabilities, invokeHelper, setHelperManager } from '@ember/helper';

import type { resource } from './resource';
import type { Cache } from './types';
import type Owner from '@ember/owner';

type SpreadFor<T> = T extends Array<any> ? T : [T];
type ResourceFactory<Value = any, Args = any[]> = (...args: SpreadFor<Args>) => Value;
type ResourceFactory<Value = any, Args = any> = (...args: SpreadFor<Args>) => Value;

interface State {
cache: Cache;
Expand Down Expand Up @@ -134,13 +135,55 @@ class ResourceInvokerManager {
* })
* ```
*/
export function resourceFactory<Value = any, Args = any>(
wrapperFn: ResourceFactory<Value, Args>
): (args: () => Args) => Value {
export function resourceFactory<Value = unknown, Args extends unknown[] = unknown[]>(
wrapperFn: (...args: Args) => ReturnType<typeof resource<Value>>
/**
* This is a bonkers return type.
* Here are the scenarios:
* const A = resourceFactory((...args) => {
* return resource(({ on }) => {
* ...
* })
* })
*
* Invocation styles need to be type-correct:
* @use a = A(() => [b, c, d])
* => single argument which is a function where the return type is the args
*
* {{#let (A b c d) as |a|}}
* {{a}}
* {{/let}}
* => args are passed directly as positional arguments
*/
) {
setHelperManager(ResourceInvokerFactory, wrapperFn);

return wrapperFn as unknown as (args: () => Args) => Value;
return wrapperFn as ResourceBlueprint<Value, Args>;
}

type ResourceBlueprint<Value, Args> =
/**
* type for JS invocation with @use
* @use a = A.from(() => [b, c, d])
*/
| ((thunk: () => SpreadFor<Args>) => ReturnType<typeof resource<Value>>)
/**
* Type for template invocation
* {{#let (A b c d) as |a|}}
* {{a}}
* {{/let}}
*/
| ((...args: SpreadFor<Args>) => ReturnType<typeof resource<Value>>)
/**
* Not passing args is allowed, too
* @use a = A.from()
*
* {{A}}
*/
| (() => ReturnType<typeof resource<Value>>)
// semicolon
;


// Provide a singleton manager.
const ResourceInvokerFactory = (owner: Owner) => new ResourceInvokerManager(owner);
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
"lint": "pnpm run --filter '*' lint:js --fix"
},
"devDependencies": {
"@changesets/changelog-github": "^0.4.7",
"@changesets/cli": "^2.25.2",
"@nullvoxpopuli/eslint-configs": "^3.0.0",
"concurrently": "^7.2.1",
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.0",
"@nullvoxpopuli/eslint-configs": "^3.1.3",
"concurrently": "^7.6.0",
"eslint": "^7.32.0",
"loader.js": "^4.7.0",
"prettier": "^2.7.1",
"typescript": "^4.7.3"
"prettier": "^2.8.4",
"typescript": "^4.9.5"
},
"volta": {
"node": "18.14.2",
Expand All @@ -42,7 +42,7 @@
},
"peerDependencyRules": {
"ignoreMissing": [
"msw"
"msw", "webpack"
],
"allowedVersions": {
"typescript": "*"
Expand Down
Loading