Closed fgm closed 5 years ago
Thanks @FGM - pull requests are welcome!
Thanks for drawing up this plan! I don't want to oversubscribe you, but if you learn anything during your investigation, or are inspired enough to also document the facts
package while you're already in there, it would be great to improve your documentation on this! There's a long-standing issue open on the docs repository!
I sent a PR to show how I envision things. It's just a first draft to make sure we're on the same page (hence the [WIP]. I think it is best not to touch the docs for now, to keep the change as small as can be.
At this point, the PR passes the CI tests, and in an app (simple-todos), the server-side works, but not the ui. Checking.
PR working on our side, there are a few questions on the PR itself, though.
I guess this should be closed now.
I was thinking of adding a "set" based facts (to supplement the "increment" model). Any interest in that?
Basically, that would mean adding something like this:
Facts.setServerFact = function (pkg, fact, value) {
if (!hasOwn.call(factsByPackage, pkg)) {
factsByPackage[pkg] = {};
factsByPackage[pkg][fact] = value;
activeSubscriptions.forEach(function (sub) {
sub.added(FACTS_COLLECTION, pkg, factsByPackage[pkg]);
});
return;
}
const packageFacts = factsByPackage[pkg];
factsByPackage[pkg][fact] = value;
const changedField = {};
changedField[fact] = factsByPackage[pkg][fact];
activeSubscriptions.forEach(function (sub) {
sub.changed(FACTS_COLLECTION, pkg, changedField);
});
};
I'm thinking of using that to provide information like:
import os from 'os';
const cpus = os.cpus();
{
hostname: os.hostname(),
osType: os.type(),
osPlatform: os.platform(),
osRelease: os.release(),
arch: os.arch(),
cpus,
}
// and in a setInterval...
{
loadavg: os.loadavg().map(x => x / cpus.length),
totalMem: os.totalmem(),
freeMem: os.freemem(),
upTime: os.uptime(),
}
This makes me think of the current https://github.com/fgm/meteor_server_info (from which this issue/PR originally came). Did you look at it ?
Just did. Looks nice albeit more complicated than what I would like.
Still, my objective is to be able to add "text facts". Already have added get/set methods on a local version of facts-base
, but I do think those features are broadly applicable.
If you can think of any way to simplify it, I'm interested (on the issue queue over there, not here of course). I was mentioning it because of the type of facts you took as an example.
I believe the original feature here has been implemented in #9629. (Thank you, @fgm!) If there's desire for new additions to the facts
package, we should open those up as new feature requests and discuss them there.
Thanks!
git clone https://github.com/meteor/meteor && cat packages/facts/package.js
Description of the problem
The Facts package provides two unrelated services:
facts-base
)facts-ui
)Expected behavior
Have the UI be an optional package (
facts-ui
) or find a way to make it available only if templating is present, instead of requiring it. The list of dependencies should then just be:Actual behavior
All applications using this package bring in this whole list of dependencies:
Suggested fix
Convert to a wrapper package for compatibility (
facts
), use two separate packages (facts-base
andfacts-ui
). I can submit a PR.