Skip to content
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

Optimizations and bug fix #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions GlobalEventEmitter.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,21 @@ var listeners = {};
DeviceEventEmitter.addListener('onNotification', (data) => {
var notifName = data.name;
var notifData = data.userInfo;

for (var i=0; i<listeners[notifName].length; i++) {
var listener = listeners[notifName][i];
listener(notifData);
};
});

function addListener(eventName, callback) {
var callBacks = [];
if (listeners[eventName]) {
callBacks = listeners[eventName];
listeners[eventName].push(callback);
}

callBacks.push(callback);

listeners[eventName] = callBacks;
RNTGlobalEventEmitter.addObserver(eventName);
else {
listeners[eventName] = [callback];
RNTGlobalEventEmitter.addObserver(eventName);
}
return listeners[eventName].indexOf(callback);
};

function emit(eventName, data) {
Expand All @@ -46,19 +44,21 @@ function removeListener(eventName, callbackRef) {
};
}

function removeListenderById(eventName, Id) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id small i

listeners[eventName].splice(Id, 1);
}

function removeAllListeners(eventName) {
RNTGlobalEventEmitter.removeObserver(eventName);
delete listeners[eventName];
if (!listeners.length) {
DeviceEventEmitter.removeAllListeners('onNotification');
};
}

var DeviceMotion = {
addListener,
emit,
removeListener,
removeAllListeners,
removeListenderById
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spelling

};

DeviceMotion.UIApplicationNotifications = RNTGlobalEventEmitter.UIApplicationNotifications;
Expand Down