Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a batching orderable directive #36

Open
faassen opened this issue Sep 9, 2016 · 0 comments
Open

a batching orderable directive #36

faassen opened this issue Sep 9, 2016 · 0 comments

Comments

@faassen
Copy link
Member

faassen commented Sep 9, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant