shmck
shmck

Reputation: 5609

Meteor Package: Add Custom Options

I've created a Meteor smart package, and would like to add user generated custom options to the API.

However, I'm having issues due to Meteor's automatic load ordering.

SocialButtons.config({
  facebook: false
});

This runs a config block that adds defaults.

SocialButtons.config = function (options) {
  ... add to options if valid ...
};

Which in turn grabs a set of defaults:

var defaults = {
  facebook: true,
  twitter: true
}

Which are mixed into the settings.

var settings = _.extend(defaults, options);

...(program starts, uses settings)...

The problem is that everything must run in the proper order.

  1. Create SocialButtons object
  2. Run the optional SocialButtons.config()
  3. Create settings & run the program

How can I control the load order in Meteor without knowing where a user might place the optional configuration?

Step 2 will be in a different folder/file, but must run sandwiched between steps 1 & 3.

Upvotes: 0

Views: 60

Answers (2)

shmck
shmck

Reputation: 5609

Figured this out.

  1. Put your package into a /lib directory.
  2. Include a setup function that sets the settings when called, and loads the data
  3. Return the data from the startup function

In this case:

SocialButtons.get = function () {
   return initButtons();
}

function initButtons() { ... settings, startup, return final value ... }

Upvotes: 0

user5084201
user5084201

Reputation:

You can't really control load order right now so it's not guaranteed but placing files at /libs are loaded first but in your case it's doesn't really matter it might be something else here is a very simple package you can view the source on how I setup default options and allow to replace those easily https://github.com/voidale/meteor-bootstrap-alerts

Upvotes: 0

Related Questions