Skip to content

a batching orderable directive #36

@faassen

Description

@faassen

In Morepath we have, for instance in case of predicates, a situation were take the directive's configuration, stuff it into a separate registry, and then in after take that registry, sort what's in it (by information given to the directive), and finally flow it into the "real" registry.

It strikes me that we could generalize this into Dectate: collected dectate actions of a class are sorted against a sorting algorithm first before they are actually performed.

Let's analyze the use cases in Morepath:

  • with predicates we also have the predicate fallback directive, which affects the same registration state. So more is going on than just storing a directive and storing.
  • with template directories there is the whole hacky configurable passing in. The actually sorting of template directories takes place in the template_loader action.
  • with tween factory the sorting only happens at the last moment during runtime in App.publish.

The interactions between different directives make the above generalization proposal insufficient. Perhaps we can instead generalize the registries that are used to record and sort information something that is specified directly by a special kind of action. So perhaps we need a generalized configuration
object to support this use case. Something like:

def sort_tweens(tweens):
    ... topological sort tweens by over and under ...
    ... could generalize it some more by specifying on what attributes
    ... to do topological sort instead

@App.directive('tween_factory')
class TweenFactoryAction(dectate.OrderedAction):
    config = {
        'tween_registry': dectate.OrderedRegistry(sort_tweens)
    }

    def __init__(self, under=None, over=None, name=None):
        global tween_factory_id
        self.under = under
        self.over = over
        if name is None:
            name = u'tween_factory_%s' % tween_factory_id
            tween_factory_id += 1
        self.name = name

    def identifier(self, tween_registry):
        return self.name

   # default perform that stores action and obj in OrderedRegistry

# elsewhere

config.tween_registry.get_sorted_values()

Even so this won't work completely for predicates, where multiple directives work together to construct the information needed. But we could still use this by storing predicate fallbacks in a supplementary registry.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions