-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #144 from NullVoxPopuli/additional-utilities
Introduce useHelper, update automation blueprint
- Loading branch information
Showing
14 changed files
with
424 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,46 @@ | ||
name: Types | ||
|
||
# based on: | ||
# - https://github.com/NullVoxPopuli/eslint-plugin-decorator-position/blob/master/.github/workflows/lint.yml | ||
# - https://github.com/NullVoxPopuli/ember-autostash-modifier/blob/master/.github/workflows/ci.yml | ||
# - https://github.com/emberjs/ember-test-helpers/blob/master/.github/workflows/ci-build.yml | ||
name: "Types" | ||
on: | ||
pull_request: | ||
push: | ||
# filtering branches here prevents duplicate builds from pull_request and push | ||
branches: | ||
- main | ||
- master | ||
|
||
env: | ||
CI: true | ||
|
||
jobs: | ||
types: | ||
install_dependencies: | ||
if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')" | ||
name: Type Checking | ||
name: Install Dependencies | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 15 | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: volta-cli/action@v1 | ||
- uses: actions/checkout@v2 | ||
- uses: volta-cli/action@v1 | ||
- uses: actions/cache@v2 | ||
with: | ||
path: '**/node_modules' | ||
key: ${{ runner.os }}-modules-${{ hashFiles('**/package-lock.json') }} | ||
- run: npm install | ||
|
||
- run: npm install | ||
types: | ||
if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')" | ||
name: "Type Correctness" | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 5 | ||
needs: [install_dependencies] | ||
|
||
- name: Type Checking | ||
# run: yarn tsc --build | ||
run: npm run prepack | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: volta-cli/action@v1 | ||
- uses: actions/cache@v2 | ||
with: | ||
path: '**/node_modules' | ||
key: ${{ runner.os }}-modules-${{ hashFiles('**/package-lock.json') }} | ||
- run: npm run prepack | ||
# - run: yarn tsc --build | ||
# - run: npm run prepack | ||
# - run: npm exec tsc --build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* eslint-disable @typescript-eslint/ban-types */ | ||
// typed-ember has not publihsed types for this yet | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
import { getValue } from '@glimmer/tracking/primitives/cache'; | ||
// typed-ember has not publihsed types for this yet | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
import { invokeHelper } from '@ember/helper'; | ||
|
||
import { DEFAULT_THUNK, normalizeThunk } from './utils'; | ||
|
||
import type { Cache, Thunk } from './types'; | ||
import type { helper as emberFunctionHelper } from '@ember/component/helper'; | ||
import type Helper from '@ember/component/helper'; | ||
|
||
export function useHelper( | ||
context: object, | ||
helper: Helper | ReturnType<typeof emberFunctionHelper>, | ||
thunk: Thunk = DEFAULT_THUNK | ||
) { | ||
let resource: Cache<unknown>; | ||
|
||
return { | ||
get value(): unknown { | ||
if (!resource) { | ||
resource = invokeHelper(context, helper, () => { | ||
return normalizeThunk(thunk); | ||
}) as Cache<unknown>; | ||
} | ||
|
||
return getValue<unknown>(resource)!; // eslint-disable-line | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.