Comparing version 8.0.4 to 8.0.5
@@ -5,2 +5,11 @@ # Changelog | ||
### [8.0.5](https://github.com/hybridsjs/hybrids/compare/v8.0.4...v8.0.5) (2022-06-20) | ||
### Bug Fixes | ||
* **router:** support parameter in first part of the URL ([7a86cbc](https://github.com/hybridsjs/hybrids/commit/7a86cbcb8ce27f9378209cf8e87b5548e5020400)) | ||
* **store:** add client-side validation for boolean values ([e473689](https://github.com/hybridsjs/hybrids/commit/e473689c3b263fc9939c324bbe4c048cc5312574)) | ||
* **store:** prevent iterating over the previous model props ([f5a5673](https://github.com/hybridsjs/hybrids/commit/f5a567338ab6eadbf69d5e5e94329afff2b158b4)) | ||
### [8.0.4](https://github.com/hybridsjs/hybrids/compare/v8.0.3...v8.0.4) (2022-05-16) | ||
@@ -7,0 +16,0 @@ |
@@ -286,11 +286,11 @@ # API Reference | ||
```typescript | ||
store.value(defaultValue: string | number, validate?: fn | RegExp, errorMessage?: string): String | Number | ||
store.value(defaultValue: string | number | boolean, validate?: fn | RegExp, errorMessage?: string): String | Number | Boolean | ||
``` | ||
- **arguments**: | ||
- `defaultValue` - `string` or `number` value | ||
- `defaultValue` - `string`, `number` or `boolean` | ||
- `validate` - a validation function - `validate(val, key, model)`, which should return `false`, error message or throws when validation fails, or a RegExp instance. If omitted, the default validation is used, which fails for empty string and `0`. | ||
- `errorMessage` - optional error message used when validation fails | ||
- **returns**: | ||
- a `String` or `Number` instance | ||
- a `String`, `Number` or `Boolean` instance | ||
@@ -297,0 +297,0 @@ ### Resolve |
@@ -135,3 +135,3 @@ # Model | ||
The store supports client-side validation for `string` and `number` primitive values, which is called for `store.set()` action. If it fails, the instance won't be updated, and an error will be attached to the instance. The rejected `Error` instance contains the `err.errors` object, where all of the validation errors are listed by the property names (you can read more about how to use it in the [Usage](./usage.md#draft-mode) section). | ||
The store provides client-side validation for supported primitive values, which is called within `store.set()` action. If it fails, the instance won't be updated, and an error will be attached to the instance. The rejected `Error` instance contains the `err.errors` object, where all of the validation errors are listed by the property names (you can read more about how to use it in the [Usage](./usage.md#draft-mode) section). | ||
@@ -144,2 +144,3 @@ To set the property with the validation use the` store.value()` method instead of passing the default value directly: | ||
count: store.value(0, (val) => val > 10, "Value must be bigger than 10"), | ||
termsAndConditions: store.value(false), | ||
..., | ||
@@ -150,11 +151,11 @@ }; | ||
```typescript | ||
store.value(defaultValue: string | number, validate?: fn | RegExp, errorMessage?: string): String | Number | ||
store.value(defaultValue: string | number | boolean, validate?: fn | RegExp, errorMessage?: string): String | Number | Boolean | ||
``` | ||
* **arguments**: | ||
* `defaultValue` - `string` or `number` value | ||
* `defaultValue` - `string`, `number` or `boolean` | ||
* `validate` - a validation function - `validate(val, key, model)`, which should return `false`, error message or throws when validation fails, or a RegExp instance. If omitted, the default validation is used, which fails for empty string and `0`. | ||
* `errorMessage` - optional error message used when validation fails | ||
* **returns**: | ||
* a `String` or `Number` instance | ||
* a `String`, `Number` or `Boolean` instance | ||
@@ -161,0 +162,0 @@ ### Computed Value |
{ | ||
"name": "hybrids", | ||
"version": "8.0.4", | ||
"version": "8.0.5", | ||
"description": "A JavaScript framework for creating fully-featured web applications, components libraries, and single web components with unique declarative and functional architecture", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -128,3 +128,3 @@ import global from "./global.js"; | ||
return `${acc}/${part}`; | ||
}); | ||
}, ""); | ||
@@ -131,0 +131,0 @@ const url = new URL(temp, global.location.origin); |
@@ -379,3 +379,7 @@ /* eslint-disable no-use-before-define */ | ||
if (defaultValue instanceof String || defaultValue instanceof Number) { | ||
if ( | ||
defaultValue instanceof String || | ||
defaultValue instanceof Number || | ||
defaultValue instanceof Boolean | ||
) { | ||
const check = validationMap.get(defaultValue); | ||
@@ -1418,2 +1422,6 @@ if (!check) { | ||
break; | ||
case "boolean": | ||
// eslint-disable-next-line no-new-wrappers | ||
defaultValue = new Boolean(defaultValue); | ||
break; | ||
default: | ||
@@ -1445,2 +1453,11 @@ throw TypeError( | ||
function cloneModel(model) { | ||
const config = definitions.get(model); | ||
const clone = Object.freeze(Object.create(model)); | ||
definitions.set(clone, config); | ||
return clone; | ||
} | ||
function store(Model, options = {}) { | ||
@@ -1524,3 +1541,3 @@ const config = bootstrap(Model); | ||
if (nextValue !== value && ready(value) && !ready(nextValue)) { | ||
const tempValue = config.create(value); | ||
const tempValue = cloneModel(value); | ||
cache.set(tempValue, "state", () => getModelState(nextValue)); | ||
@@ -1527,0 +1544,0 @@ return tempValue; |
@@ -183,2 +183,7 @@ declare module "hybrids" { | ||
): number; | ||
function value<M>( | ||
defaultValue: boolean, | ||
validate?: ValidateFunction<M, number> | RegExp, | ||
errorMessage?: string, | ||
): boolean; | ||
} | ||
@@ -185,0 +190,0 @@ |
415794
6281