From 6f4af1b24bc692c5ef923bc8f1ff32f264faca78 Mon Sep 17 00:00:00 2001 From: Adam Baker Date: Wed, 11 Jan 2023 12:38:53 -0500 Subject: [PATCH] Enhance submit arg --- ember-validations/package.json | 4 +- .../src/components/form-validator/index.ts | 4 +- test-app/app/controllers/application.ts | 17 +----- test-app/app/routes/application.ts | 15 ++++- test-app/app/templates/application.hbs | 1 + test-app/package.json | 6 +- yarn.lock | 55 ++++++++++--------- 7 files changed, 54 insertions(+), 48 deletions(-) diff --git a/ember-validations/package.json b/ember-validations/package.json index 364052b..3340046 100644 --- a/ember-validations/package.json +++ b/ember-validations/package.json @@ -50,8 +50,8 @@ "@babel/runtime": "^7.16.7", "@ember/render-modifiers": "^2.0.4", "@embroider/addon-dev": "^1.7.1", - "@glint/core": "^0.9.2", - "@glint/environment-ember-loose": "^0.9.2", + "@glint/core": "^0.9.7", + "@glint/environment-ember-loose": "^0.9.7", "@rollup/plugin-babel": "^5.3.1", "@types/ember-data__model": "^4.0.0", "@types/ember-resolver": "^5.0.11", diff --git a/ember-validations/src/components/form-validator/index.ts b/ember-validations/src/components/form-validator/index.ts index 646d9e8..4c4f667 100644 --- a/ember-validations/src/components/form-validator/index.ts +++ b/ember-validations/src/components/form-validator/index.ts @@ -14,7 +14,7 @@ import FormValidatorChild from './child'; interface FormValidatorArgs, V = ValueForChangeset> { changeset: C; - submit: (changesets: [C, GenericChangeset[]] | [C]) => void; + submit: (parent: C, children?: GenericChangeset[]) => void; } export type BoundInputValidator, V = ValueForChangeset> = WithBoundArgs< @@ -118,7 +118,7 @@ export default class FormValidator, V = ValueForCh try { await all(validations); - return this.args?.submit([ownChangeset, children.changesets]); + return this.args?.submit(ownChangeset, children.changesets); } catch (error) { this.showAllValidationFields = true; this.childValidators.forEach((item) => { diff --git a/test-app/app/controllers/application.ts b/test-app/app/controllers/application.ts index cdcf0ec..e61c2a8 100644 --- a/test-app/app/controllers/application.ts +++ b/test-app/app/controllers/application.ts @@ -3,25 +3,14 @@ import { action } from '@ember/object'; import { GenericChangeset } from '@gavant/ember-validations/utilities/create-changeset'; -import Application, { RouteModel } from 'test-app/routes/application'; +import Application, { RouteModel, TestChangeset } from 'test-app/routes/application'; export default class ApplicationController extends Controller { declare model: RouteModel; declare childChangeset: GenericChangeset<{ foo: string }>; + @action - submitForm([parent, children]: [ - GenericChangeset<{ - name: null; - num: string; - radio: null; - nestedItem: { - much: { - wow: null; - }; - }; - }>, - [GenericChangeset<{ foo: string }>] - ]) { + submitForm(parent: TestChangeset, children: [typeof this.childChangeset]) { parent.name; children[0].foo; window.alert('submitted succesfully!'); diff --git a/test-app/app/routes/application.ts b/test-app/app/routes/application.ts index c543dee..55eb2d0 100644 --- a/test-app/app/routes/application.ts +++ b/test-app/app/routes/application.ts @@ -3,7 +3,7 @@ import Route from '@ember/routing/route'; import { validateNumber, validatePresence } from 'ember-changeset-validations/validators'; -import createChangeset from '@gavant/ember-validations/utilities/create-changeset'; +import createChangeset, { GenericChangeset } from '@gavant/ember-validations/utilities/create-changeset'; import ApplicationController from 'test-app/controllers/application'; @@ -22,6 +22,17 @@ const Validations = { const childValidations = { foo: [validatePresence({ presence: true, ignoreBlank: true })] }; + +export type TestChangeset = GenericChangeset<{ + name: null; + num: string; + radio: null; + nestedItem: { + much: { + wow: null; + }; + }; +}>; export default class Application extends Route { validations = Validations; @@ -39,7 +50,7 @@ export default class Application extends Route { }, Validations ); - return changeset; + return changeset as TestChangeset; } setupController(controller: ApplicationController, model: RouteModel, transition: Transition) { diff --git a/test-app/app/templates/application.hbs b/test-app/app/templates/application.hbs index 8de6e79..78cb016 100644 --- a/test-app/app/templates/application.hbs +++ b/test-app/app/templates/application.hbs @@ -2,6 +2,7 @@

Welcome to Ember

+ {{! template-lint-disable no-passed-in-event-handlers }} diff --git a/test-app/package.json b/test-app/package.json index 00b86ef..ee3359f 100644 --- a/test-app/package.json +++ b/test-app/package.json @@ -34,8 +34,8 @@ "@embroider/webpack": "^1.8.3", "@glimmer/component": "^1.1.2", "@glimmer/tracking": "^1.1.2", - "@glint/core": "^0.9.2", - "@glint/environment-ember-loose": "^0.9.2", + "@glint/core": "^0.9.7", + "@glint/environment-ember-loose": "^0.9.7", "@types/ember-resolver": "^5.0.11", "@types/ember__application": "^4.0.0", "@types/ember__array": "^4.0.1", @@ -98,7 +98,7 @@ "qunit": "^2.19.1", "qunit-dom": "^2.0.0", "sass": "^1.53.0", - "typescript": "^4.7.4", + "typescript": "^4.9.4", "webpack": "^5.73.0" }, "engines": { diff --git a/yarn.lock b/yarn.lock index 6c0898e..9c1192e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1645,23 +1645,23 @@ "@glimmer/interfaces" "^0.42.2" "@glimmer/util" "^0.42.2" -"@glint/config@^0.9.4": - version "0.9.4" - resolved "https://registry.yarnpkg.com/@glint/config/-/config-0.9.4.tgz#969b1d75e8c02ba92cca52e3e388aceadc150748" - integrity sha512-ip8lVWvdQYoxKQWessol9Lw8xwqp8y3DjKurXQqC9P9Hi2lnPQC2IoOAI565wRj8SnWrxBA1FCLVxtAWRGgADQ== +"@glint/config@^0.9.7": + version "0.9.7" + resolved "https://registry.yarnpkg.com/@glint/config/-/config-0.9.7.tgz#43077e9cd2743d3bb66f6c4670681c49644ac139" + integrity sha512-XkWIZ3fuOlcofUJUaJmRS57mVVNi+Af2HtrZkBXEOCh4+BNz2wclxv2WKvkhmtvLhEUOhHb5eU3gwI58SuwgXQ== dependencies: escape-string-regexp "^4.0.0" minimatch "^3.0.4" resolve "^1.17.0" silent-error "^1.1.1" -"@glint/core@^0.9.2": - version "0.9.4" - resolved "https://registry.yarnpkg.com/@glint/core/-/core-0.9.4.tgz#147b77313f8841948390c86298ae501891408e76" - integrity sha512-7n7nUV/kbRQ6y5AhWyO2NO1J79/h3zaBn2BJ1NXaguUvQY70/YvM15CeA4JfsrFjR8Yr2Y175QfP0Ug4MSD89Q== +"@glint/core@^0.9.7": + version "0.9.7" + resolved "https://registry.yarnpkg.com/@glint/core/-/core-0.9.7.tgz#887dbdfa10d89702549de36197cc2eb0783a5c86" + integrity sha512-1YLHNRnuYI1dDUKWq/ue4JqiBt6TVR8e7VQJWy37CKB0tiBhWw/FPvr7/S7XbUxCt6KHO0Kl0x/eqLunu3WiQw== dependencies: - "@glint/config" "^0.9.4" - "@glint/transform" "^0.9.4" + "@glint/config" "^0.9.7" + "@glint/transform" "^0.9.7" resolve "^1.17.0" uuid "^8.3.2" vscode-languageserver "^8.0.1" @@ -1669,26 +1669,26 @@ vscode-uri "^3.0.2" yargs "^17.5.1" -"@glint/environment-ember-loose@^0.9.2": - version "0.9.4" - resolved "https://registry.yarnpkg.com/@glint/environment-ember-loose/-/environment-ember-loose-0.9.4.tgz#e95d1c64c0ab9866b8c8d46c590f3b915171eb31" - integrity sha512-70S8BwpfoOuoGRUvmsIF1be5vmYhzVzSnXRraa0UG6ZJm4WyrP1OqJEdl5sXTsKLsF/Gp8Fb5hc3dibP4GluNw== +"@glint/environment-ember-loose@^0.9.7": + version "0.9.7" + resolved "https://registry.yarnpkg.com/@glint/environment-ember-loose/-/environment-ember-loose-0.9.7.tgz#8d27e93d6bd3afd59c46acad27a2c3130045dee0" + integrity sha512-MlCGZtB1Clp4vQWIm2APSnCm7nL8wVhFMOhVy2qzpV0nfLyg3pcN9CQHNpfdJvCydBB72cA4/ahPj7VEFL6xsg== dependencies: - "@glint/config" "^0.9.4" - "@glint/template" "^0.9.4" + "@glint/config" "^0.9.7" + "@glint/template" "^0.9.7" -"@glint/template@^0.9.4": - version "0.9.4" - resolved "https://registry.yarnpkg.com/@glint/template/-/template-0.9.4.tgz#b1df5f379d569169abd26a3cf927a2510ea2fd7f" - integrity sha512-MiIcFyTT7SeXhkv0WK4/s/LW9Go1E2FGf8xu+4/1PeSPfSgAbEgRqIXHdtIreeFQhVrAwFFGff/+eHZkRgZWsA== +"@glint/template@^0.9.7": + version "0.9.7" + resolved "https://registry.yarnpkg.com/@glint/template/-/template-0.9.7.tgz#8736f357482841962bc66e75831f189f33677165" + integrity sha512-MCp8GxQDIbH8ZzfNxHhVqCSKlydBgQfBEwJLDpN81lgFRCldSDPueIbk8sz3EhpGiZJVdNQbpGeYIDsUXe1ocg== -"@glint/transform@^0.9.4": - version "0.9.4" - resolved "https://registry.yarnpkg.com/@glint/transform/-/transform-0.9.4.tgz#5350901b2b840dccbc160349fe88f9486002ecab" - integrity sha512-RgK+Rm2fs+djH5jur5KGTcOTWMoPMJx1GB/6ksIXBDq8jA4l4V0ZKZR/GQ5B2NBlfzf7UqWPRb0LNff7grAVHg== +"@glint/transform@^0.9.7": + version "0.9.7" + resolved "https://registry.yarnpkg.com/@glint/transform/-/transform-0.9.7.tgz#01c60249c1fe6663955d2acd2cf7625a551fb3f3" + integrity sha512-vd0th+Zo4cirYepASpC0fE0ZCqAcI9Y6qHYE0xi4+MY05bFRxBr7Q9ggDoWk+slynTyUrVgzCCeazAYOlZsYcg== dependencies: "@glimmer/syntax" "^0.84.2" - "@glint/config" "^0.9.4" + "@glint/config" "^0.9.7" "@handlebars/parser@~2.0.0": version "2.0.0" @@ -13511,6 +13511,11 @@ typescript@^4.7.4: resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.4.tgz#1a88596d1cf47d59507a1bcdfb5b9dfe4d488235" integrity sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ== +typescript@^4.9.4: + version "4.9.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.4.tgz#a2a3d2756c079abda241d75f149df9d561091e78" + integrity sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg== + ua-parser-js@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-1.0.2.tgz#e2976c34dbfb30b15d2c300b2a53eac87c57a775"