realm-js/lib/collection-methods.js
Maximilian Alexander 775bd8e2ff adding ts and package.json typings (#1076)
* adding ts and package.json typings

* remove DefinitelyTyped needed comments, we are hosting this ourselves

* adding licensing comments

* Added initial contribution support

Thanks @akim95

* changing year

* adding parameters

* Expand on collection typings

* update the windows pre-gyp script (#1072)

* Extract admin status from the refresh token (#1078)

* Extract admin status from the refresh token

Fixes #1063

* wire up rpc

* Make sure all callbacks enqueue on the Node.js event loop (#1079)

Fixes #1077

* Use an uncached realm instance for _waitForDownload (#1083)

Fixes #1061

* Add objectSchema method to Realm Object (#1055)

* Add objectSchema property to Realm Object

* fix

* fixes

* move typings under lib/

* changelog
2017-06-20 13:09:01 +02:00

93 lines
2.5 KiB
JavaScript

////////////////////////////////////////////////////////////////////////////
//
// Copyright 2016 Realm Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////
'use strict';
var arrayPrototype = Array.prototype;
// eslint-disable-next-line no-undef
var iteratorPrototype = {};
// These iterators should themselves be iterable.
Object.defineProperty(iteratorPrototype, Symbol.iterator, {
value: function() {
return this;
}
});
[
'toString',
'toLocaleString',
'concat',
'join',
'slice',
'indexOf',
'lastIndexOf',
'every',
'some',
'forEach',
'find',
'findIndex',
'map',
'filter',
'reduce',
'reduceRight',
].forEach(function(methodName) {
var method = arrayPrototype[methodName];
if (method) {
exports[methodName] = {value: method, configurable: true, writable: true};
}
});
['entries', 'keys', 'values'].forEach(function(methodName) {
var method = function() {
var self = this;
var index = 0;
return Object.create(iteratorPrototype, {
next: {
value: function() {
if (!self || index >= self.length) {
self = null;
return {done: true, value: undefined};
}
var value;
switch (methodName) {
case 'entries':
value = [index, self[index]];
break;
case 'keys':
value = index;
break;
default:
value = self[index];
}
index++;
return {done: false, value: value};
}
}
});
};
exports[methodName] = {value: method, configurable: true, writable: true};
});
exports[Symbol.iterator] = exports.values;