src/core/registry.coffee in luca-0.9.42 vs src/core/registry.coffee in luca-0.9.65

- old
+ new

@@ -2,33 +2,38 @@ classes:{} model_classes: {} collection_classes: {} namespaces:['Luca.containers','Luca.components'] -component_cache = +componentCacheStore = cid_index: {} name_index: {} # For container views, if a component is defined with no ctype # then we will pick this one when using -Luca.defaultComponentType = 'view' +Luca.config.defaultComponentClass = Luca.defaultComponentClass = 'Luca.View' +Luca.config.defaultComponentType = Luca.defaultComponentType = 'view' Luca.registry.aliases = - grid: "grid_view" - form: "form_view" - text: "text_field" - button: "button_field" - select: "select_field" - card: "card_view" - paged: "card_view" - wizard: "card_view" - collection: "collection_view" + grid: "grid_view" + form: "form_view" + text: "text_field" + button: "button_field" + select: "select_field" + card: "card_view" + paged: "card_view" + wizard: "card_view" + collection: "collection_view" + list: "collection_view" + multi: "collection_multi_view" + table: "table_view" + # When you use _.def to define a component, you say # which class it extends() from, and with() which enhancements. # We register that component class for you: -Luca.register = (component, prototypeName, componentType="view")-> +Luca.registerComponent = (component, prototypeName, componentType="view")-> Luca.trigger "component:registered", component, prototypeName switch componentType when "model" registry.model_classes[ component ] = prototypeName @@ -46,19 +51,19 @@ liveInstances = Luca.registry.findInstancesByClassName( prototypeName ) _( liveInstances ).each (instance)-> instance?.refreshCode?.call(instance, prototypeDefinition) - Luca.register( component, prototypeName ) + Luca.registerComponent( component, prototypeName ) # We create a @ctype alias for this component definition, and register # the class in a registry. # If you use a custom namespace like MyApp.views.ListView, # then we will register MyApp.views as a namespace. You can # do this yourself too. -Luca.registry.addNamespace = (identifier)-> +Luca.registry.addNamespace = Luca.registry.namespace = (identifier)-> registry.namespaces.push( identifier ) registry.namespaces = _( registry.namespaces ).uniq() # This allows us to declare relationships between objects at definition time # and have the instances of these objects be created at runtime when they @@ -91,39 +96,47 @@ fullPath = _( parents ).chain().map (parent)-> parent[className] .compact().value()?[0] Luca.registry.instances = ()-> - _( component_cache.cid_index ).values() - + _( componentCacheStore.cid_index ).values() + +Luca.registry.findInstancesByClass = (componentClass)-> + Luca.registry.findInstancesByClassName( componentClass.displayName ) + Luca.registry.findInstancesByClassName = (className)-> + className = className.displayName if not _.isString( className ) instances = Luca.registry.instances() _( instances ).select (instance)-> + isClass = instance.displayName is className + instance.displayName is className or instance._superClass?()?.displayName is className Luca.registry.classes = (toString=false)-> _(_.extend({},registry.classes,registry.model_classes,registry.collection_classes)).map (className, ctype)-> if toString className else className: className ctype: ctype -Luca.cache = (needle, component)-> - component_cache.cid_index[ needle ] = component if component? +Luca.cache = Luca.cacheInstance = (cacheKey, object)-> + return unless cacheKey? + return object if object?.doNotCache is true - component = component_cache.cid_index[ needle ] + if object? + componentCacheStore.cid_index[ cacheKey ] = object + object = componentCacheStore.cid_index[ cacheKey ] + # optionally, cache it by tying its name to its cid for easier lookups - if component?.component_name? - component_cache.name_index[ component.component_name ] = component.cid - else if component?.name? - component_cache.name_index[ component.name ] = component.cid + if object?.component_name? + componentCacheStore.name_index[ object.component_name ] = object.cid + else if object?.name? + componentCacheStore.name_index[ object.name ] = object.cid - return component if component? + return object if object? - # perform a lookup by name if the component_id didn't turn anything - lookup_id = component_cache.name_index[ needle ] + # perform a lookup by name if the cid lookup didn't turn anything + lookup_id = componentCacheStore.name_index[ cacheKey ] - component_cache.cid_index[ lookup_id ] - - + componentCacheStore.cid_index[ lookup_id ]