-
Notifications
You must be signed in to change notification settings - Fork 577
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
Change schema definition format #20
Comments
We will need a dynamic api similar to the current implementation as this is currently being added to the other bindings. We can explore automatic schema inference but there are some big issues such as support for non-native js types (int, float, data, etc) which may be difficult to specify in an elegant way. |
I'm personally in favor of continuing to be explicit, but losing the order dependency. I like the PersonObject.schema = {
name: 'PersonObject',
properties: {
name: Realm.Types.string,
age: Realm.Types.double,
children: Realm.Types.arrayOf('PersonObject'),
// Also allow these for setting more options...
limbs: {type: Realm.Types.int, default: 4},
career: {type: Realm.Types.string, optional: true},
}
}; In addition, I think it's more appropriate to have the schema be set as a static property of the constructor rather than on the prototype. This is how React's |
Using a map rather than an array of properties looks good to me. We can't set the schema as a static property on Realm as we need to support access to multiple realms with differing schema. |
Sorry, I meant a static property of the constructor of an object rather than on its prototype. For example, inside |
So it sounds like we can't do this at the moment as we need to support column ordering in order for sync to work. In the future if the constraint is laxed then we can support the proposed format. |
So my primary issue is with the look and feel of the current API, not necessarily with the columns having intrinsic ordering. This also relates to #112, which is that I want to remove creating objects from arrays of properties. In JS, the property keys will still have ordering in my proposed new API, meaning iterating over those keys or calling |
Does JS ensure that keys will retain the ordering in which they are defined? |
Yes it is guaranteed in the language. I actually have all of this working in my |
I don't think this is guaranteed for Objects: http://stackoverflow.com/questions/5525795/does-javascript-guarantee-object-property-order |
Yes it is. Older versions of ECMAScript left it unspecified, but all engines have maintained insert order and many libraries and websites have come to depend on it, so ES6 retroactively officially added this to the specification since all engines had this behavior anyways. |
From the ES6 spec: |
You're right, I was partially mistaken. The spec doesn't require the engine use insertion order for enumerating properties, but it does require that engine to maintain insertion order since it requires |
Lets finish this this week. I think we need to make the change to the schema format. We shouldn't rip out array support and I don't think it is necessary to refactor all the tests a this time, although if there aren't any conflicts we can keep the current changes. Moving forward we can write new tests using objects rather than arrays if that is preferable, |
Fix opening read-only Realms in read-only directories
@appden :
The text was updated successfully, but these errors were encountered: