Permalink
Browse files

got rid of populateInstances in favour of lazy populating

  • Loading branch information...
1 parent 917ed9e commit 9688354ecb7e8a993cd98516dc46a8da4c930e7a Mark Evans committed Mar 21, 2012
Showing with 8 additions and 8 deletions.
  1. +8 −8 src/scope.coffee
View
@@ -5,9 +5,6 @@ class egg.Scope extends egg.Base
@parent = opts.parent
throw("Scope needs a parent") unless @parent
- @_instances = new egg.Set
- @_populateInstances()
-
# Events
@subscribe @parent, 'add', (params) =>
@_add(params.instance) if @filter(params.instance)
@@ -26,15 +23,18 @@ class egg.Scope extends egg.Base
@subscribe @parent, 'remove', (params) =>
@_remove(params.instance) if @has(params.instance)
- instances: -> @_instances
+ instances: ->
+ if @_instances
+ @_instances
+ else
+ @_instances = new egg.Set
+ @parent.instances().forEach (instance)=>
+ @_instances.add instance if @filter(instance)
+ @_instances
filter: (filter)->
@constructor.create(parent: @, filter: filter)
- _populateInstances: ->
- @parent.instances().forEach (instance)=>
- @instances().add instance if @filter(instance)
-
_add: (instance)->
@emit 'add', instance: instance if @instances().add instance

0 comments on commit 9688354

Please sign in to comment.