Jaymon / bang

A static site generator with support for RSS feeds, sitemaps, and Google Amp
MIT License
13 stars 0 forks source link

create a semaphore context event handler #41

Closed Jaymon closed 5 years ago

Jaymon commented 5 years ago

Right now, you can trigger a context.NAME event by doing:

with conf.context("NAME") as conf:
    pass

And it would be cool if you could also do something like:

with conf.context_once("NAME") as conf:
    with conf.context_once("NAME") as conf:
        pass

and context.NAME would only trigger the first time but not the second, that way you can have plugins be configured the same way but not have to call the same context configuration callback over and over again.

Other names: context_atomic()

Jaymon commented 5 years ago

Another idea would be to just make all events atomic unless you specify differently, I think that might be the better approach

Jaymon commented 5 years ago

Some notes on the new event handling system I had in the code:

        e = Event()
        e[0] # args[0]
        e["html"] # kwargs["html"]
        e.html # kwargs["html"]
        e.event_name # the event name
        e.config # the configuration

        # a callback signature would look like:
        # callback(event, config, html)
        # and event.html would point to the past, bah, that won't work, so
        # maybe:
        #
        #  callback(event, config) and config would point to event.config but
        #  everything else will be in event, so you could access html by
        #  event.html

        # let's make it so .broadcast takes (event_name, config, **kwargs) and
        # those kwargs will be available through the event instance passed into
        # the callback