Skip to content

feat: add syntax for more JSON schema type mappingΒ #7313

@janechu

Description

@janechu

πŸ™‹ Feature Request

Currently the Observer Map understands the general shape of attribute and observable data based on the bindings used inside the template. This is only in relation to objects and arrays however, as we can infer that dot syntax implies an object such that a.b, a must be an object, and the in syntax implies an array so item in items, items must be an array.

It would be convenient for Observer Map to understand primitive types and default values from a more verbose syntax. This should not be a breaking change as we can use the current defaults to string primitives.

πŸ€” Example syntax

<template>
    <input type="radio" checked="{{ isChecked | type:boolean }}" />
    <input type="number" value="{{ numValue | type:number }}" />
    <input type="text" value="{{ text | type:string }}" /><!--unnecessary but allowed as the default is string-->
</template>

The JSON schema types null and integer may not result in any specific action as they may not have use cases so we will start with string, number, and boolean.

πŸ”¦ Context

The @attr decorator allows for the specifying of values types expected however to HTML all attributes are string. This is inconvenient inside a JavaScript custom element class to have to transform the value so the @attr handles this for us. If we assign an @attr through Observer Maps, and we want this to be something other than a string, we should map this in the JSON schema so that the @attr value can be mapped precisely and the developer can recieve a number or boolean value in JavaScript.

Metadata

Metadata

Assignees

Labels

Projects

Status

Triage

Relationships

None yet

Development

No branches or pull requests

Issue actions