Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Trouble using Popcorn for changing+removing events?

37 views
Skip to first unread message

wol...@gmail.com

unread,
May 8, 2013, 10:43:59 AM5/8/13
to
Hey,
I've been using Popcorn to implement BrowserCast[0], a tool which helps turn IPython Notebooks into Powerpoint-like presentations.

I've been running into some problems, though… It's not obvious how to change and remove events once they have been created.

For example, if I write a small plugin, then create an event:

```
Popcorn.plugin("browsercastCell", { … });
myPopcornInstance.browsercastCell({
start: 5,
end: 10,

});
```

It's not clear how I can change the start/end times of that event, or how I can remove that event entirely.

Looking through the source code, the `addTrackEvent` and `removeTrackEvent` *seem* to be the functions I want… but code comments suggest that they are internal-only, and there doesn't seem to be any documentation on them, so I'm wary about using them.

So: what is the correct way to add, update, and remove events?

Thanks,
David

[0]: https://github.com/wolever/browsercast

Scott Downe

unread,
May 8, 2013, 11:23:37 AM5/8/13
to wol...@gmail.com, dev-p...@lists.mozilla.org
removeTrackEvent is fine for external use, it is just addTrackEvent that is
suggested against using. It is best to add a track event using the
constructing function of popcorn.yourtrackevent(options).

In order to remove it, you need a reference to the track event. Easiest way
to do this is getLastTrackEventId, but that's not the greatest when you're
dealing with a lot of track events.

You can create track events with your own ids, by passing the id in first.
popcorn.browsercastCell( id, {start: 1, end: 10})

Updating is possible, by calling popcorn.browsercastCell( id, {start: 1,
end: 10}) on an existing id. Instead of creating a new track event, it
updates the one registered under that id.

This removes and adds the track event again by default. If the plugin has
an _update function, it'll instead call that update function.
_update(trackEvent, newOptions)
This can let the plugin author do the heavy lifting as to what an update
means, allowing them to not do a complete teardown.

Feel free to let me know if you have any problems with any of these.
> _______________________________________________
> dev-popcorn mailing list
> dev-p...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-popcorn
>

David Wolever

unread,
May 14, 2013, 12:38:43 AM5/14/13
to
That's great — thanks a lot, Scott.

It seems like this is basically working… But I've run into a few more issues:
- Are there any examples showing how _update works? For example, if I want to update the start/end times of a track event, what do I need to do?

- I need some method to track "the last track event for my plugin that was made visible" (logically equivalent to: "events.filter(function(e) { return e.end > currentTime }).sort(function(a, b) { return a.start - b.start }).getLastElement()") — is there any reasonable way to do this? I've tried simply keeping a stack in the plugin, pushing to it each time `.start()` is called, popping from it each time `.end()` is called, but for various reasons (one of which, I think, has to do with updating the track events…), it doesn't look like there are any strong guarantees on the order of calls to `.start()`/ `.end()`.

David
0 new messages