From 336ef55c1fc953d8bb3749b85c35299b20a7a304 Mon Sep 17 00:00:00 2001 From: Scott Kyle Date: Thu, 5 Nov 2015 16:10:52 -0800 Subject: [PATCH] Remove uses of for-of loops in RPC modules The React Native packager does not transform for-of loops, and minification step uses UglifyJS, which does not yet support ES6 syntax. Fixes #120 --- lib/.eslintrc | 3 +++ lib/objects.js | 4 ++-- lib/realm.js | 4 +--- lib/util.js | 8 +++----- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/.eslintrc b/lib/.eslintrc index a7d60609c8..50abf59d0d 100644 --- a/lib/.eslintrc +++ b/lib/.eslintrc @@ -4,6 +4,9 @@ "browser": true, "es6": true, }, + "ecmaFeatures": { + "forOf": false + }, "globals": { "global": true } diff --git a/lib/objects.js b/lib/objects.js index 3d16775145..e9dea027fd 100644 --- a/lib/objects.js +++ b/lib/objects.js @@ -25,14 +25,14 @@ function create(realmId, info) { object[keys.id] = info.id; object[keys.type] = info.type; - for (let prop of schema.properties) { + schema.properties.forEach((prop) => { let name = prop.name; props[name] = { get: util.getterForProperty(name), set: util.setterForProperty(name), }; - } + }); Object.defineProperties(object, props); diff --git a/lib/realm.js b/lib/realm.js index 4c920f885b..49bdabb225 100644 --- a/lib/realm.js +++ b/lib/realm.js @@ -101,9 +101,7 @@ class Realm { rpc.commitTransaction(realmId); - for (let callback of this[listenersKey]) { - callback(this, 'change'); - } + this[listenersKey].forEach((cb) => cb(this, 'change')); } } diff --git a/lib/util.js b/lib/util.js index 71eace955b..ded21bcdd0 100644 --- a/lib/util.js +++ b/lib/util.js @@ -28,9 +28,7 @@ function addMutationListener(realmId, callback) { function fireMutationListeners(realmId) { let listeners = mutationListeners[realmId]; if (listeners) { - for (let callback of listeners) { - callback(); - } + listeners.forEach((cb) => cb()); } } @@ -97,11 +95,11 @@ function createList(prototype, realmId, info, mutable) { function createMethods(prototype, type, methodNames, mutates) { let props = {}; - for (let name of methodNames) { + methodNames.forEach((name) => { props[name] = { value: createMethod(type, name, mutates), }; - } + }); Object.defineProperties(prototype, props); }