From e2e502fce377206eded9ff137d2e6f227bfb572d Mon Sep 17 00:00:00 2001 From: Caio Marcelo de Oliveira Filho Date: Mon, 23 Sep 2013 14:18:12 -0300 Subject: [PATCH] [Notification] Do not keep separated copy of notifications Notification object is essentialy as a "property bag" to be used in conjunction with tizen.notification.* functions. Now that we have v8tools.forceSetProperty() we can keep certain properties read-only and do not need to worry about user changing the notification, so no need to keep our own copy of the data. Note that since Notification API doesn't rely on GC to identify notifications that should be removed, one needs to explicitly call the remove function, or wait for user removal via the UI. --- notification/notification_api.js | 50 ++++------------------------------------ 1 file changed, 4 insertions(+), 46 deletions(-) diff --git a/notification/notification_api.js b/notification/notification_api.js index 1d9c10f..ce38234 100644 --- a/notification/notification_api.js +++ b/notification/notification_api.js @@ -33,7 +33,7 @@ NotificationCenter.prototype.onNotificationRemoved = function(id) { NotificationCenter.prototype.wasPosted = function(notification) { var i; for (i = 0; i < this.postedNotifications.length; i++) { - if (this.postedNotifications[i].original === notification) + if (this.postedNotifications[i] === notification) return true; } return false; @@ -49,18 +49,11 @@ NotificationCenter.prototype.postNotification = function(notification) { postMessage(msg); v8tools.forceSetProperty(notification, 'postedTime', new Date); - - var posted = copyStatusNotification(notification); - posted.original = notification; - this.postedNotifications.push(posted); + this.postedNotifications.push(notification); }; NotificationCenter.prototype.getAll = function() { - var result = []; - var i; - for (i = 0; i < this.postedNotifications.length; i++) - result[i] = this.postedNotifications[i].original; - return result; + return this.postedNotifications.slice(); }; NotificationCenter.prototype.get = function(notificationId) { @@ -68,7 +61,7 @@ NotificationCenter.prototype.get = function(notificationId) { var i; for (i = 0; i < this.postedNotifications.length; i++) { if (this.postedNotifications[i].id == notificationId) { - result = this.postedNotifications[i].original; + result = this.postedNotifications[i]; break; } } @@ -159,41 +152,6 @@ tizen.StatusNotification = function(statusType, title, dict) { this.thumbnails = dict.thumbnails || []; }; -var copyStatusNotification = function(notification) { - var copy = new tizen.StatusNotification(notification.statusType, notification.title, { - content: notification.content, - iconPath: notification.iconPath, - soundPath: notification.soundPath, - vibration: notification.vibration, - appControl: notification.appControl, - appId: notification.appId, - progressType: notification.progressType, - progressValue: notification.progressValue, - number: notification.number, - subIconPath: notification.subIconPath, - ledColor: notification.ledColor, - ledOnPeriod: notification.ledOnPeriod, - ledOffPeriod: notification.ledOffPeriod, - backgroundImagePath: notification.backgroundImagePath, - thumbnails: notification.thumbnails - }); - - v8tools.forceSetProperty(copy, 'id', notification.id); - v8tools.forceSetProperty(copy, 'postedTime', notification.postedTime); - copy.detailInfo = []; - if (notification.detailInfo) { - var i; - for (i = 0; i < notification.detailInfo.length; i++) { - var info = notification.detailInfo[i]; - copy.detailInfo[i] = { - mainText: info.mainText, - subText: info.subText - }; - } - } - return copy; -}; - exports.post = function(notification) { if (!(notification instanceof tizen.StatusNotification)) { throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR); -- 2.7.4