mirror of
https://github.com/discourse/discourse.git
synced 2025-01-19 02:52:44 +08:00
adjust API
This commit is contained in:
parent
89d5e8ab4b
commit
f2099c3811
|
@ -6,11 +6,11 @@ class TopicList
|
||||||
cattr_accessor :preloaded_custom_fields
|
cattr_accessor :preloaded_custom_fields
|
||||||
self.preloaded_custom_fields = Set.new
|
self.preloaded_custom_fields = Set.new
|
||||||
|
|
||||||
def self.on_preload(blk)
|
def self.on_preload(&blk)
|
||||||
(@preload ||= Set.new) << blk
|
(@preload ||= Set.new) << blk
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.cancel_preload(blk)
|
def self.cancel_preload(&blk)
|
||||||
if @preload
|
if @preload
|
||||||
@preload.delete blk
|
@preload.delete blk
|
||||||
if @preload.length == 0
|
if @preload.length == 0
|
||||||
|
|
|
@ -36,12 +36,12 @@ describe TopicList do
|
||||||
preloaded_topic = true
|
preloaded_topic = true
|
||||||
end
|
end
|
||||||
|
|
||||||
TopicList.on_preload(preloader)
|
TopicList.on_preload(&preloader)
|
||||||
|
|
||||||
topic_list.topics
|
topic_list.topics
|
||||||
expect(preloaded_topic).to eq(true)
|
expect(preloaded_topic).to eq(true)
|
||||||
|
|
||||||
TopicList.cancel_preload(preloader)
|
TopicList.cancel_preload(&preloader)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user