Shape objects
kai zhu
kaizhu256 at gmail.com
Sat Jun 16 12:03:06 UTC 2018
> I wish JS had Shape objects, which would not only ease performance optimization for the benefit of JS engines (https://youtu.be/5nmpokoRaZI?t=871 <https://youtu.be/5nmpokoRaZI?t=871>), but also helps for validation, like an interface
>
> ```js
> shape Point { x: Number, y: Number, name: String };
>
> const p = Point({x: 1, y: 2, name: 'foo'})
>
> const p = Point({x: 1, y: 2, naem: 'foo'}) // throws
> ```
@cyril, you are thinking too low-level. given how time-constrained most web-projects are, shape-validating low-level library-code is poor-allocation of a backend-engineer’s time, that could be better spent on integration-level interfaces (e.g. browser <-> server interface) where most of these validation painpoints occur, e.g. [1]:
```http
// frontend-request
POST /api/v2/createPoint
{ "x": 1, "y": 2, "naem": "foo" }
// useless backend-response
500 Internal Server Error or TIMEOUT
// better backend-response (that can be reasonably debugged)
400
{
"message": "400 POST /api/v2/createPoint - object body must have property \"name\"",
"statusCode": 400
}
```
[1] shape-validate integration-level interfaces with swagger
https://kaizhu256.github.io/example-esdiscuss-topic-shape-objects/assets.swgg.html <https://kaizhu256.github.io/example-esdiscuss-topic-shape-objects/assets.swgg.html>
kai zhu
kaizhu256 at gmail.com
> On 16 Jun 2018, at 2:30 AM, Bob Myers <rtm at gol.com> wrote:
>
> The engines already do these optimizations.
>
>
> On Sat, Jun 16, 2018 at 1:27 PM Cyril Auburtin <cyril.auburtin at gmail.com <mailto:cyril.auburtin at gmail.com>> wrote:
> I wish JS had Shape objects, which would not only ease performance optimization for the benefit of JS engines (https://youtu.be/5nmpokoRaZI?t=871 <https://youtu.be/5nmpokoRaZI?t=871>), but also helps for validation, like an interface
>
> ```js
> shape Point { x: Number, y: Number, name: String };
>
> const p = Point({x: 1, y: 2, name: 'foo'})
>
> const p = Point({x: 1, y: 2, naem: 'foo'}) // throws
> ```
>
> That object would have its properties immutable
>
> I think proposal-first-class-protocols (https://github.com/michaelficarra/proposal-first-class-protocols/issues/27#issuecomment-386975099 <https://github.com/michaelficarra/proposal-first-class-protocols/issues/27#issuecomment-386975099>) could more or less directly do that feature
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org <mailto:es-discuss at mozilla.org>
> https://mail.mozilla.org/listinfo/es-discuss <https://mail.mozilla.org/listinfo/es-discuss>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180616/c8aeccb4/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2018-06-16 at 4.25.17 AM copy.jpg
Type: image/jpeg
Size: 41598 bytes
Desc: not available
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180616/c8aeccb4/attachment-0002.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2018-06-16 at 4.45.15 AM copy.jpg
Type: image/jpeg
Size: 52526 bytes
Desc: not available
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180616/c8aeccb4/attachment-0003.jpg>
More information about the es-discuss
mailing list