#919 ✓ staged
Bobby Richter

Add a `toString` method to plugins

Reported by Bobby Richter | February 16th, 2012 @ 09:01 AM | in 1.2 (closed)

We've come across an issue in Butter (https://webmademovies.lighthouseapp.com/projects/65733-butter/ticke...) where events have tooltips to display quick details about them.

Obviously, we can just parse the options object and grab data, but it turns out to be ugly usually.

A few people have suggested adding a toString method to plugins to which we initially resisted, but it seems it would satisfy our problem optimally.

Comments and changes to this ticket

  • Rick

    Rick February 16th, 2012 @ 09:38 AM

    • Assigned user set to “Rick”

    I'm inclined to think this is a fairly reasonable request. Can you show us some example use case pseudo-ish code? Are you thinking about something along these lines: https://github.com/secretrobotron/butter/pull/13/files#diff-0 ?

    Here are a few questions that will help me with implementing something that is actually useful for you:

    • What kind of information about the plugin would you like to see?

    • Will it be "per plugin"?

    • Or "per track event"?

  • cadecairos

    cadecairos February 16th, 2012 @ 11:31 AM

    I'm thinking this would be a per plugin deal.

    We'd need to decide on a case to case basis what each plugin considers to be important information to return from toString().

    I'd suggest it not go over 3 or 4 lines.

  • Rick

    Rick February 16th, 2012 @ 11:48 AM

    Ok, so basically adding an interface that plugin authors can define the return value of?

  • cadecairos

    cadecairos February 16th, 2012 @ 11:55 AM

    Yeah, I think that's the best way to go.

    popcorn.plugin( "foo", function( options ) {
      start: function( ops ) {},
      end: function( ops ) {},
      toString: function( ops ) {}
    });
    

    something like that maybe?

  • Bobby Richter

    Bobby Richter February 16th, 2012 @ 12:20 PM

    • I think it's got to be per-track-event because data can change between them. Useful for finding out what's in a specific event on the timeline
    • What Chris has suggested will probably work. Just return something from a toString fn that you think is most useful for your plugin. Perhaps, if there is an absence of toString, Popcorn can fill it in with a formatted options, but that's not entirely necessary.
    • Ideally, the string returned would say something about time, and other important properties specific to the plugin type.
  • Rick

    Rick February 16th, 2012 @ 12:23 PM

    Ok, I'll prototype a feature then, we're probably going to need to iterate on this one

  • Rick

    Rick February 16th, 2012 @ 12:34 PM

    Update...

    The good news is that plugins can have a toString defined in their options without changing any code in the core or in the plugin source itself, accessible via the track event that is created - check this out:

    http://jsfiddle.net/rwaldron/vtNFV/

    That being said, I'm prototyping the feature and have some test written to support the following addition to the plugin factory:

    
    if ( !( "toString" in options ) ) {
      options.toString = function() {
        var data = {
          id: options._id,
          start: options.start,
          end: options.end
        };
    
        return JSON.stringify( data );
      };
    }
    

    What else would you like to see for reasonable defaults in that data object?

  • cadecairos

    cadecairos February 16th, 2012 @ 12:44 PM

    the only other possibly safe default I can think of is target, assuming the plugin author used "target" as the identifier... which could cause issues if they did not.

  • Bobby Richter

    Bobby Richter February 16th, 2012 @ 01:11 PM

    So, the plan is to just supply the toString method when you create events?

    Is there a way to push this into the plugins themselves?

  • Rick

    Rick February 16th, 2012 @ 01:30 PM

    Bobby, well, see my example - we can add "reasonable" defaults very easily which will give all track events a toString() - I'm asking you to help me define what qualifies as a "reasonable default"

  • Bobby Richter

    Bobby Richter February 16th, 2012 @ 05:19 PM

    Yeah, I saw that default bit, but it's less useful than a human just deciding what's good to have in their plugin's description :/.

    If it has to be automated like that, I would say start, end, and target are nice to haves, but even target isn't always available, right? At the very minimum, I'd say start & end. What else can we say, for certain, will be there 99% of the time?

  • Rick

    Rick February 16th, 2012 @ 05:36 PM

    I think you're looking at this from the wrong perspective. You can already define a toString() on your plugin options arguments and then retrieve it from the track event object. I'm trying to make it so that Popcorn will give you one for free, but allow you to override it with your own toString(), if you want.

    It doesn't have to be automated like anything, I'm just trying to meet your needs the best way possible.

  • Jon Buckley

    Jon Buckley February 16th, 2012 @ 05:39 PM

    I'd say id, target, start, and end as a default toString() method makes the most sense.

  • Rick
  • Rick

    Rick February 16th, 2012 @ 06:00 PM

    • State changed from “new” to “peer-review-requested”
    • Assigned user changed from “Rick” to “Bobby Richter”

    Give it a spin!

    https://github.com/rwldrn/popcorn-js/tree/t919

    git checkout -b t919 && git pull git://github.com/rwldrn/popcorn-js.git t919

  • Bobby Richter

    Bobby Richter February 16th, 2012 @ 06:25 PM

    I see what you did there! Understood. I was thinking of something like this:

      Popcorn.plugin( "something" , {
        _setup: function( options ) {
        },
        start: function( event, options ){
        },
        end: function( event, options ){
        },
        _teardown: function( options ) {
        },
        toString: function( options ){
          return options.start + ", " + options.end + ": " + options.foo;
        }
      });
    

    but, as you suggested, this probably works just as well:

      Popcorn.plugin( "something" , {
        _setup: function( options ) {
          options.toString = function(){
            return options.start + ", " + options.end + ": " + options.foo;
        },
        start: function( event, options ){
        },
        end: function( event, options ){
        },
        _teardown: function( options ) {
        }
      });
    

    I think they're functionally equivalent; we don't have to create a toString() for ourselves whenever we create an event and the plugin's author can decide what's important to share. The only thing I'm trying to avoid is having the user pick what gets displayed by default.

    So, regardless of which method we pick, might a requisite for this ticket be making the plugins have a toString method where possible?

  • Scott Downe

    Scott Downe February 24th, 2012 @ 04:44 PM

    Interesting. Is it correct to say, that because this is on the options object, it can be unique on a track by track basis if the plugin author is so inclined?

    I am not sure of the use case for that, but I like the organic-ness and dynamic-ness of it.

    I do like where this is going. Sign me up for the super-review.

  • Bobby Richter

    Bobby Richter February 24th, 2012 @ 04:46 PM

    • State changed from “peer-review-requested” to “super-review-requested”
    • Assigned user changed from “Bobby Richter” to “Scott Downe”

    Looks good to me. PR+

    New tickets for plugin-specifics.

  • Scott Downe

    Scott Downe February 27th, 2012 @ 12:18 PM

    • State changed from “super-review-requested” to “review-looks-good”
    • Assigned user changed from “Scott Downe” to “cadecairos”
  • cadecairos

    cadecairos February 29th, 2012 @ 12:36 PM

    • State changed from “review-looks-good” to “staged”
    • Assigned user changed from “cadecairos” to “Rick”

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Popcorn.js is an HTML5 video framework that lets you bring elements of the web into your videos.

Popcorn.js is a project of Web Made Movies, Mozilla's Open Video Lab.

Shared Ticket Bins

Referenced by

Pages