Socket
Socket
Sign inDemoInstall

@lion/field

Package Overview
Dependencies
Maintainers
1
Versions
103
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lion/field - npm Package Compare versions

Comparing version 0.1.23 to 0.1.24

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

## [0.1.24](https://github.com/ing-bank/lion/compare/@lion/field@0.1.23...@lion/field@0.1.24) (2019-07-02)
### Bug Fixes
* **field:** don't return Unparseable on empty strings ([6a85dbc](https://github.com/ing-bank/lion/commit/6a85dbc))
## [0.1.23](https://github.com/ing-bank/lion/compare/@lion/field@0.1.22...@lion/field@0.1.23) (2019-07-02)

@@ -8,0 +19,0 @@

4

package.json
{
"name": "@lion/field",
"version": "0.1.23",
"version": "0.1.24",
"description": "Fields are the most fundamental building block of the Form System",

@@ -44,3 +44,3 @@ "author": "ing-bank",

},
"gitHead": "e2a1986630108e02ecbfbb742bab6df6d5dfd32e"
"gitHead": "0cdd0c22209ed0b1cd58951fae4273408e0761da"
}

@@ -185,7 +185,33 @@ /* eslint-disable class-methods-use-this */

__callParser(value = this.formattedValue) {
let result;
if (typeof value === 'string') {
result = this.parser(value, this.formatOptions);
// A) check if we need to parse at all
// A.1) The end user had no intention to parse
if (value === '') {
// Ideally, modelValue should be undefined for empty strings.
// For backwards compatibility we return an empty string:
// - it triggers validation for required validators (see ValidateMixin.validate())
// - it can be expected by 3rd parties (for instance unit tests)
// TODO: In a breaking refactor of the Validation System, this behaviot can be corrected.
return '';
}
return typeof result !== 'undefined' ? result : new Unparseable(value);
// A.2) Handle edge cases We might have no view value yet, for instance because
// inputElement.value was not available yet
if (typeof value !== 'string') {
// This means there is nothing to find inside the view that can be of
// interest to the Application Developer or needed to store for future form state
// retrieval.
return undefined;
}
// B) parse the view value
// - if result:
// return the successfully parsed viewValue
// - if no result:
// Apparently, the parser was not able to produce a satisfactory output for the desired
// modelValue type, based on the current viewValue. Unparseable allows to restore all
// states (for instance from a lost user session), since it saves the current viewValue.
const result = this.parser(value, this.formatOptions);
return result !== undefined ? result : new Unparseable(value);
}

@@ -192,0 +218,0 @@

@@ -215,3 +215,3 @@ import { expect, fixture, html, aTimeout, defineCE, unsafeStatic } from '@open-wc/testing';

it('will only call the parser for string values', async () => {
it('will only call the parser for defined values', async () => {
const parserSpy = sinon.spy();

@@ -225,6 +225,23 @@ const el = await fixture(html`

expect(parserSpy.callCount).to.equal(1);
// This could happen for instance in a reset
el.modelValue = undefined;
expect(parserSpy.callCount).to.equal(1);
// This could happen when the user erases the input value
mimicUserInput(el, '');
expect(parserSpy.callCount).to.equal(1);
});
it('will not return Unparseable when empty strings are inputted', async () => {
const el = await fixture(html`
<${elem}>
<input slot="input" value="string">
</${elem}>
`);
// This could happen when the user erases the input value
mimicUserInput(el, '');
// For backwards compatibility, we keep the modelValue an empty string here.
// Undefined would be more appropriate 'conceptually', however
expect(el.modelValue).to.equal('');
});
it('will only call the formatter for valid values on `user-input-changed` ', async () => {

@@ -231,0 +248,0 @@ const formatterSpy = sinon.spy(value => `foo: ${value}`);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc