Skip to content
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

Maps are not supportable #63

Open
blloyd75 opened this issue Mar 15, 2015 · 2 comments
Open

Maps are not supportable #63

blloyd75 opened this issue Mar 15, 2015 · 2 comments

Comments

@blloyd75
Copy link

With the current implementation, maps are not easily supported. A traditional javascript object or backbone object easily implements the map<string, value> model. However, nestedTypes cannot handle a typed map, where the attribute names may be random strings but the value is a fixed type.

Code like myObj[key].refnum is valid JavaScript, very useful, but cannot be easily done through the nestedTypes framework. Untyped maps can be used as a value for a field, but since field names MUST be predefined for an object, the closest to this structure that can be done is an object with a Collection of sub-objects where the key is an attribute of the sub-object.

@gaperton
Copy link

I don't understand the problem. For untyped map attribute, you can not only use plain object, like this

var M = Model.extend({
    defaults : {
        yourMap : {}
    }
})

but you can use every object constructor as a type. If plain object is not suitable for you for some reason, create your own object constructor for your map and go ahead.

var M = Model.extend({
    defaults : {
        yourMap : YourMap
    }
})

:)

@gaperton
Copy link

And yes, in contrast to plain Backbone, models in NestedTypes cannot be used as maps. Separate Map type can be created, however, we didn't needed it yet. Because all rare cases maps are needed can be handled with plain objects and custom types. So, I may do it in spare time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants