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: ->
|
constructor: ->
|
||||||
super
|
super
|
||||||
@title 'Form'
|
@title 'Form'
|
||||||
@subscribeId = App.Setting.subscribe(@render, initFetch: true)
|
@subscribeId = App.Setting.subscribe(@render, initFetch: true, clear: false)
|
||||||
|
|
||||||
render: =>
|
render: =>
|
||||||
App.Setting.unsubscribe(@subscribeId)
|
App.Setting.unsubscribe(@subscribeId)
|
||||||
|
|
|
@ -5,20 +5,7 @@ class App.SettingsArea extends App.Controller
|
||||||
# check authentication
|
# check authentication
|
||||||
return if !@authenticate()
|
return if !@authenticate()
|
||||||
|
|
||||||
@load()
|
@subscribeId = App.Setting.subscribe(@render, initFetch: true, clear: false)
|
||||||
|
|
||||||
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()
|
|
||||||
)
|
|
||||||
|
|
||||||
render: =>
|
render: =>
|
||||||
|
|
||||||
|
|
|
@ -85,16 +85,23 @@ class _collectionSingleton extends Spine.Module
|
||||||
return
|
return
|
||||||
|
|
||||||
# load data from object
|
# load data from object
|
||||||
|
listToRefresh = []
|
||||||
for key, object of params.data
|
for key, object of params.data
|
||||||
if !params.refresh && appObject
|
if !params.refresh && appObject
|
||||||
|
@log 'debug', 'refrest try', params.type, key
|
||||||
|
|
||||||
# check if new object is newer, just load newer objects
|
# check if new object is newer, just load newer objects
|
||||||
if object.updated_at && appObject.exists(key)
|
if object.updated_at && appObject.exists(key)
|
||||||
exists = appObject.find(key)
|
exists = appObject.find(key)
|
||||||
if exists.updated_at
|
if exists.updated_at
|
||||||
if exists.updated_at < object.updated_at
|
if exists.updated_at < object.updated_at
|
||||||
appObject.refresh(object)
|
listToRefresh.push object
|
||||||
|
@log 'debug', 'refrest newser', params.type, key
|
||||||
else
|
else
|
||||||
appObject.refresh(object)
|
listToRefresh.push object
|
||||||
|
@log 'debug', 'refrest try no updated_at', params.type, key
|
||||||
else
|
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
|
# fetch init collection
|
||||||
if param.initFetch is true
|
if param.initFetch is true
|
||||||
|
clear = true
|
||||||
|
if param.clear is true || param.clear is false
|
||||||
|
clear = param.clear
|
||||||
if !@initFetchActive
|
if !@initFetchActive
|
||||||
@one 'refresh', (collection) =>
|
@one 'refresh', (collection) =>
|
||||||
@initFetchActive = true
|
@initFetchActive = true
|
||||||
callback(collection)
|
callback(collection)
|
||||||
@fetchFull(
|
@fetchFull(
|
||||||
->
|
->
|
||||||
clear: true
|
clear: clear
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
callback(@all())
|
callback(@all())
|
||||||
|
|
|
@ -6,14 +6,6 @@ class SettingsController < ApplicationController
|
||||||
# GET /settings
|
# GET /settings
|
||||||
def index
|
def index
|
||||||
return if deny_if_not_role(Z_ROLENAME_ADMIN)
|
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)
|
model_index_render(Setting, params)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue