Use regex instead of simple substring (#2075)

This commit is contained in:
Nikola Irinchev 2018-10-16 15:45:59 +02:00 committed by GitHub
parent 142c626e4f
commit 7cc4e0feee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

@ -5,7 +5,7 @@ x.x.x Release notes (yyyy-MM-dd)
### Fixed
* <How to hit and notice issue? what was the impact?> ([#????](https://github.com/realm/realm-js/issues/????), since v?.?.?)
* None.
* Fixed an incorrect property named returned from `Realm.subscriptions()`. (since v2.19.0-rc.2)
### Compatibility
* Realm Object Server: 3.11.0 or later.

View File

@ -27,6 +27,8 @@ let getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors || function(obj
}, {});
};
const subscriptionObjectNameRegex = /^(class_)?(.*?)(_matches)?$/gm;
function setConstructorOnPrototype(klass) {
if (klass.prototype.constructor !== klass) {
Object.defineProperty(klass.prototype, 'constructor', { value: klass, configurable: true, writable: true });
@ -393,7 +395,7 @@ module.exports = function(realmConstructor) {
let matches_property = subscription['matches_property'];
let sub = {
name: subscription['name'],
objectType: matches_property.substr(0, matches_property.length-8), // remove _matches
objectType: matches_property.replace(subscriptionObjectNameRegex, '$2'),
query: subscription['query'],
}
listOfSubscriptions.push(sub);