Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using third party javascript package with Meteor

Tags:

meteor

I'm working with Meteor at the moment, and I'm trying to make it look more 'real timey' by adding transitions to numbers as they change. The best third party package I can see for that is http://github.hubspot.com/odometer/.

I'm having trouble getting the package to work in Meteor to update comment numbers on an item.

I've tried putting the javascript into client/compatibility as per the meteor docs: http://docs.meteor.com/#structuringyourapp, but no joy.

The other issue might be that the package uses CSS transitions, which would mean that a re-rendering of the template around the number that is updating would prevent the transition from occurring. To try and fix this problem, I used {{#isolate}} around the number, but that didn't work either.

Has anyone got any other ideas on what else in meteor might be getting in the way?

like image 461
Pat Avatar asked Oct 12 '13 23:10

Pat


People also ask

How use NPM package meteor?

To use an npm package from a file in your application you import the name of the package: import moment from 'moment'; // this is equivalent to the standard node require: const moment = require('moment'); This imports the default export from the package into the symbol moment .

How do you make a Meteor project?

The Meteor build process is configured almost entirely through adding and removing packages to your app and putting files in specially named directories. For example, to get all of the newest stable ES2015 JavaScript features in your app, you add the ecmascript package.


1 Answers

I think you should try {{#constant}} instead of {{#isolate}}. Also note, that the "constant" part of your template will no longer be reactive, so you'll have to update it manually. Supposing that you have a template

<template name="myTemplate">
    {{#constant}}
    <span class="odometer"></span>
    {{/constant}}
</template>

you will need to do something like this:

Template.myTemplate.rendered = function () {
    var node = this.find('.odometer');
    Deps.autorun(function () {
        node.innerHtml = MyCollection.find({}).count();
    });   
}
like image 154
Tomasz Lenarcik Avatar answered Sep 22 '22 05:09

Tomasz Lenarcik