-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Primitive Map Type #10
Comments
I like the idea but I would rather use something like `cars: Map` and rely
on the built-in implementation of `Map` (
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map
).
…On Mon, Jan 15, 2018 at 9:13 AM, Austin Kelleher ***@***.***> wrote:
I think that having a Map primitive would be useful. Example:
const Map = require('fashion-model/Map')const Model = require('fashion-model/Model')
const Car = Model.extend({
properties: {
id: String,
name: String
}
})
const CarMap = Map.create({
key: String,
value: Car,
keyProperty: 'id',
prototype: {
getCarById (id) {
return this.get(id)
}
}
})
const Person = Model.extend({
properties: {
name: String,
cars: CarMap
}
})
const person = Person.wrap({
name: 'John',
cars: [new Car({ id: 'abc123', name: 'Tesla' })]
// Also passing a standard key/value pair object is supported:
//
// cars: { 'abc123': new Car(...), ... }
})
console.log(person.getCars()) // { 'abc123': { id: 'abc123', name: 'Tesla' } }console.log(person.getCars().getCarById('abc123')) // { id: 'abc123', name: 'Tesla' }
Thoughts @philidem <https://github.com/philidem>?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#10>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/ACSL_gDfj2PUdyRX-GBf1qDjD3XBH3Uiks5tK10VgaJpZM4ReeGz>
.
|
The whole reason for wanting this features is to be able to do runtime validation on the key/value for what is set in the Map. If we rely on the built-in implementation of |
Oh, I read the original proposal too quickly. I do think we should try to provide a way for not having to create a Maybe this instead: const Person = Model.extend({
properties: {
name: String,
cars: {type: Map, valueType: Car}
}
}) |
If a property is a For example: person.getCars().set('blah', {year: 2018, make: 'Tesla', model: 'Model 3'}) // second argument would be coerced into a car |
I think that having a
Map
primitive would be useful. Example:Thoughts @philidem?
The text was updated successfully, but these errors were encountered: