Jelajahi Sumber

perf: only rerender changed sync service

Gerald 9 tahun lalu
induk
melakukan
02402eb36c
5 mengubah file dengan 15 tambahan dan 5 penghapusan
  1. 2 0
      src/cache.js
  2. 2 3
      src/options/app.js
  3. 7 0
      src/options/model.js
  4. 4 0
      src/options/views/sync-service.js
  5. 0 2
      src/popup/app.js

+ 2 - 0
src/cache.js

@@ -76,3 +76,5 @@ var BaseView = Backbone.View.extend({
     };
     };
   },
   },
 });
 });
+
+BaseView.prototype.postrender.call(window);

+ 2 - 3
src/options/app.js

@@ -26,7 +26,6 @@ var app = new App();
 if (!Backbone.history.start())
 if (!Backbone.history.start())
   app.navigate('', {trigger: true, replace: true});
   app.navigate('', {trigger: true, replace: true});
 
 
-BaseView.prototype.postrender.call(window);
 $(document).on('click', '[data-feature]', function (e) {
 $(document).on('click', '[data-feature]', function (e) {
   var target = e.currentTarget;
   var target = e.currentTarget;
   _.features.hit(target.dataset.feature);
   _.features.hit(target.dataset.feature);
@@ -36,12 +35,12 @@ $(document).on('click', '[data-feature]', function (e) {
 var scriptList, syncData;
 var scriptList, syncData;
 function initMain() {
 function initMain() {
   scriptList = new ScriptList;
   scriptList = new ScriptList;
-  syncData = new Backbone.Collection;
+  syncData = new SyncList;
   var port = chrome.runtime.connect({name: 'Options'});
   var port = chrome.runtime.connect({name: 'Options'});
   port.onMessage.addListener(function (res) {
   port.onMessage.addListener(function (res) {
     switch (res.cmd) {
     switch (res.cmd) {
     case 'sync':
     case 'sync':
-      syncData.reset(res.data);
+      syncData.set(res.data);
       break;
       break;
     case 'add':
     case 'add':
       res.data.message = '';
       res.data.message = '';

+ 7 - 0
src/options/model.js

@@ -42,3 +42,10 @@ var ScriptList = Backbone.Collection.extend({
     });
     });
   },
   },
 });
 });
+
+var SyncModel = Backbone.Model.extend({
+  idAttribute: 'name',
+});
+var SyncList = Backbone.Collection.extend({
+  model: SyncModel,
+});

+ 4 - 0
src/options/views/sync-service.js

@@ -4,6 +4,10 @@ var SyncServiceView = BaseView.extend({
   events: {
   events: {
     'click .sync-start': 'retry',
     'click .sync-start': 'retry',
   },
   },
+  initialize: function () {
+    BaseView.prototype.initialize.call(this);
+    this.listenTo(this.model, 'change', this.render);
+  },
   _render: function () {
   _render: function () {
     var it = this.model.toJSON();
     var it = this.model.toJSON();
     it.enabled = _.options.get(it.name + 'Enabled');
     it.enabled = _.options.get(it.name + 'Enabled');

+ 0 - 2
src/popup/app.js

@@ -18,8 +18,6 @@ var app = new App();
 if (!Backbone.history.start())
 if (!Backbone.history.start())
   app.navigate('', {trigger: true, replace: true});
   app.navigate('', {trigger: true, replace: true});
 
 
-BaseView.prototype.postrender.call(window);
-
 !function () {
 !function () {
   function commandClick(e, model) {
   function commandClick(e, model) {
     chrome.tabs.sendMessage(app.currentTab.id, {
     chrome.tabs.sendMessage(app.currentTab.id, {