Reduced amount of refresh (-> rerender) events.
This commit is contained in:
parent
6953ae52af
commit
abb049ecec
5 changed files with 16 additions and 27 deletions
|
@ -12,7 +12,7 @@ class App.ChannelForm extends App.Controller
|
|||
constructor: ->
|
||||
super
|
||||
@title 'Form'
|
||||
@subscribeId = App.Setting.subscribe(@render, initFetch: true)
|
||||
@subscribeId = App.Setting.subscribe(@render, initFetch: true, clear: false)
|
||||
|
||||
render: =>
|
||||
App.Setting.unsubscribe(@subscribeId)
|
||||
|
|
|
@ -5,20 +5,7 @@ class App.SettingsArea extends App.Controller
|
|||
# check authentication
|
||||
return if !@authenticate()
|
||||
|
||||
@load()
|
||||
|
||||
load: ->
|
||||
@startLoading()
|
||||
@ajax(
|
||||
id: "setting_area_#{@area}"
|
||||
type: 'GET'
|
||||
url: "#{@apiPath}/settings/area/#{@area}"
|
||||
processData: true
|
||||
success: (data, status, xhr) =>
|
||||
@stopLoading()
|
||||
App.Collection.load( sessionStorage: false, type: 'Setting', data: data )
|
||||
@render()
|
||||
)
|
||||
@subscribeId = App.Setting.subscribe(@render, initFetch: true, clear: false)
|
||||
|
||||
render: =>
|
||||
|
||||
|
|
|
@ -85,16 +85,23 @@ class _collectionSingleton extends Spine.Module
|
|||
return
|
||||
|
||||
# load data from object
|
||||
listToRefresh = []
|
||||
for key, object of params.data
|
||||
if !params.refresh && appObject
|
||||
@log 'debug', 'refrest try', params.type, key
|
||||
|
||||
# check if new object is newer, just load newer objects
|
||||
if object.updated_at && appObject.exists(key)
|
||||
exists = appObject.find(key)
|
||||
if exists.updated_at
|
||||
if exists.updated_at < object.updated_at
|
||||
appObject.refresh(object)
|
||||
listToRefresh.push object
|
||||
@log 'debug', 'refrest newser', params.type, key
|
||||
else
|
||||
appObject.refresh(object)
|
||||
listToRefresh.push object
|
||||
@log 'debug', 'refrest try no updated_at', params.type, key
|
||||
else
|
||||
appObject.refresh(object)
|
||||
listToRefresh.push object
|
||||
@log 'debug', 'refrest new', params.type, key
|
||||
return if _.isEmpty(listToRefresh)
|
||||
appObject.refresh(listToRefresh)
|
||||
|
|
|
@ -335,13 +335,16 @@ class App.Model extends Spine.Model
|
|||
|
||||
# fetch init collection
|
||||
if param.initFetch is true
|
||||
clear = true
|
||||
if param.clear is true || param.clear is false
|
||||
clear = param.clear
|
||||
if !@initFetchActive
|
||||
@one 'refresh', (collection) =>
|
||||
@initFetchActive = true
|
||||
callback(collection)
|
||||
@fetchFull(
|
||||
->
|
||||
clear: true
|
||||
clear: clear
|
||||
)
|
||||
else
|
||||
callback(@all())
|
||||
|
|
|
@ -6,14 +6,6 @@ class SettingsController < ApplicationController
|
|||
# GET /settings
|
||||
def index
|
||||
return if deny_if_not_role(Z_ROLENAME_ADMIN)
|
||||
|
||||
# only serve requested items
|
||||
if params[:area]
|
||||
model_index_render_result( Setting.where(area: params[:area]) )
|
||||
return
|
||||
end
|
||||
|
||||
# serve all items
|
||||
model_index_render(Setting, params)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue