Comments (13)
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.
from realm-js.
I'm personally in favor of continuing to be explicit, but losing the order dependency. I like the React.PropTypes
API overall, so I think we could model the schema representation to be similar...
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 propTypes
works, and won't cause issues with someone creating a schema
property on objects. Furthermore, perhaps it would be safer to be even more explicit by instead naming this property realmSchema
(just a thought).
from realm-js.
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.
from realm-js.
Sorry, I meant a static property of the constructor of an object rather than on its prototype. For example, inside TestObjects.js
the PersonObject
class would have schema
(or realmSchema
) set directly on PersonObject
rather than PersonObject.prototype
.
from realm-js.
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.
from realm-js.
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 Object.keys
will always be in the order as defined. The only issue is that encoding those into JSON makes them lose their ordering (since JSON keys have unspecified ordering), so we'd need to change the RPC serializing and deserializing techniques to retain the ordering over those keys, which is quite easy. 😄
from realm-js.
Does JS ensure that keys will retain the ordering in which they are defined?
from realm-js.
Yes it is guaranteed in the language. I actually have all of this working in my sk-schema-api
branch.
from realm-js.
I don't think this is guaranteed for Objects: http://stackoverflow.com/questions/5525795/does-javascript-guarantee-object-property-order
from realm-js.
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 realm-js.
From the ES6 spec:
The mechanics and order of enumerating the properties is not specified
from realm-js.
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 Object.getOwnPropertyNames(object)
to return property names in insertion order.
from realm-js.
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,
from realm-js.
Related Issues (20)
- Upgrade to Realm Core 14.5.0 HOT 1
- Random SIGSEGV error and crash on production HOT 2
- Error Realm initialization with sync enabled due to mismatch schema is not calling onError function HOT 9
- Version mismatch does not block sync HOT 5
- Run React Native integration tests in more configurations HOT 2
- Cannot index a property using TypeScript HOT 8
- Electron crash on exit (Segmentation fault, MacOS) HOT 5
- Upgrade to Realm Core 14.5.1 HOT 1
- Add ability to pass a configured Realm instance to RealmProvider HOT 2
- The binary file is not permitted. HOT 13
- TypeError: Cannot read property 'size' of undefined HOT 17
- Upgrade to Realm Core v14.5.2 HOT 1
- Cannot find module 'realm' from *** while using jest HOT 2
- Getting Error “Sync session became inactive” unhandled error HOT 5
- calling stream.return() on chrome 124 crashes browser HOT 19
- Required PrivacyInfo.xcprivacy - NSPrivacyAccessedAPICategoryFileTimestamp AND NSPrivacyAccessedAPICategoryDiskSpace HOT 16
- The "bundle install & & RCT_NEW_ARCH_ENABLED=1 bundle exec pod install" command results in the error "Could not find the Realm binary." HOT 12
- React Native Crash on compilation HOT 3
- [realm/react] investigating skipped tests HOT 2
- Enable and implement the tests for `App.updateBaseUrl()` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from realm-js.