How to stop warnings for functions without DefinitelyTyped? - meteor

If some function or library does not have DefinitelyTyped, I know these two ways to stop warnings.
interface Navigator {
getUserMedia: any
}
declare let RTCIceCandidate: any;
But right now, this 3rd-part library Collection2 is used like this:
let ProductSchema = {};
let Products = new Mongo.Collection('products');
Products.attachSchema(ProductSchema);
It give me a warning:
Property 'attachSchema' does not exist on type 'Collection'.
I tried the way below, but it does not work.
interface Collection {
attachSchema: any
}
How can I stop this warning? Thanks
EDIT:
Eric's adding any way solves the problem.
let Products:any = new Mongo.Collection('products');
Products.attachSchema(ProductSchema);
But now a new trouble comes:
let UserSchema = {};
Meteor.users.attachSchema(UserSchema);
Since Meteor.users is built in, so there is no place to add any. How to solve this? Thanks

Thanks for Amid's help. So the way is:
(<any>Meteor.users).attachSchema(UserSchema);

Related

How do I force the native version of google-closure-compiler to be used?

I can import the closure-compiler like this:
const ClosureCompiler = require('google-closure-compiler').compiler;
but that uses the java version. I have a limitation on the build machines at work such that I can't make use of java. I was hoping to force the compilation to use the native version. I've tried doing something like this:
const ClosureCompiler = require('google-closure-compiler-osx').compiler;
That seems to result in ClosureCompiler being undefined. I've gone around and around trying to find any documentation on the API exposed to javascript but I keep coming up with nothing.
If anyone has an idea about how to force native compilation rather than java compilation it would be much appreciated.
I think I've made some progress on this by looking at what's going on in the cli.js and util.js files inside node_modules/google-closer-compiler.
This pattern appears to be working:
const ClosureCompiler = require('google-closure-compiler').compiler,
compilerInstance = new ClosureCompiler({... setup opts ...});
// Force native compilation
let compilerPlatform = 'linux';
switch (process.platform) {
case 'win32': compilerPlatform = 'windows'; break;
case 'darwin': compilerPlatform = 'osx'; break;
}
compilerInstance.JAR_PATH = null;
compilerInstance.javaPath = require('google-closure-compiler-' + compilerPlatform);
compilerInstance.run((exitCode, stdOut, stdErr) => {
... do some stuff ...
});

Why is my localized variable keep saying undefined?

I am little new to wordpress. I have tried so many different attempts trying to make this work but can seem to resolve the issue.
It keeps saying that ML_MOVIE_LISTING is undefined, when i try to localize it.
Below is my php code and javascript file.
Any help would really appreciated. Thanks!
function admin_scripts (){
wp_enqueue_style("admin-style",plugins_url("style-admin.css",__FILE__));
wp_enqueue_style("jquery-ui","https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.0/external/jquery/jquery.js");
wp_enqueue_script("main_js",plugins_url("main.js",__FILE__),["jquery","jquery-ui-sortable"]);
wp_localize_script("ml-script","ML_MOVIE_LISTING",[
"token"=>wp_create_nonce("ml-token")
]);
}
add_action("admin_init","admin_scripts");
JS CODE
jQuery(document).ready(function($){
var movie_sort_list = $(".movie-sort-list"),
order_save_msg = $(".order-save-msg"),
order_save_error = $(".order-save-err");
console.log(ML_MOVIE_LISTING);
}
I just found out the reason why it wasn't working was because the name in the first parameter was different then the name of the first paramaeter in
wp_enqueue_script() They both have to be the same as shown below
wp_enqueue_script("main_js",plugins_url("main.js",__FILE__),["jquery","jquery-ui-sortable"]);
wp_localize_script("main_js","ML_MOVIE_LISTING",[
"token"=>wp_create_nonce("ml-token")
]);

Meteor - Reactive Objects/Classes

TLDR
I like to really focus on keeping business logic away from the view model / controller. I find this sometimes rather hard in Meteor. Maybe I'm missing the point but I am after one of two things really:
1) A really good document explaining at a really low level how reactive values are being used.
2) A package that somehow manages an object so that if any of the setters are altered, they notify all of the get functions that would change as a result.
Unfortunately I've not seen either.
My Example
I have a fair bit ob business logic sitting behind a dialog used to document a consultation. I might have an event that sets a change of state.
I'd like to do something like this in the event:
const cc = new ConsultationEditor();
cc.setChiefComplaint(event.target.value);
console.log(cc.data());
ConsultationDict.set("consEdit", cc.data() );
When the user has updated this value, I'd then like to show a number of fields, based on the change. For this I have a helper with the following:
fields: function(){
console.log("trying to get fields");
const obj = ConsultationDict.get('consEdit');
cc = new ConsultationEditor(obj);
return cc.getFields();
}
But unfortunately this does not work for me.
What is your ConsultationDict?
The way you describe it, you want it to be a ReactiveDict as in the official ReactiveDict package.
https://atmospherejs.com/meteor/reactive-dict
Check this tutorial for examples:
https://themeteorchef.com/snippets/reactive-dict-reactive-vars-and-session-variables/
If you really need more fine tuning in your reactivity, you can also set a dependency tracker tracker = new Tracker.Dependency, and then refer to it wherever you change a variable with tracker.changed() and where the data needs to be notified with tracker.depend() like this:
var favoriteFood = "apples";
var favoriteFoodDep = new Tracker.Dependency;
var getFavoriteFood = function () {
favoriteFoodDep.depend();
return favoriteFood;
};
var setFavoriteFood = function (newValue) {
favoriteFood = newValue;
favoriteFoodDep.changed();
};
getFavoriteFood();
See the full Tracker doc here:
https://github.com/meteor/meteor/wiki/Tracker-Manual
I also found this gist to be useful to build reactive objects:
https://gist.github.com/richsilv/7d66269aab3552449a4c
and for a ViewModel type of behavior, check out
https://viewmodel.meteor.com/
I hope this helps.

JSHint and "Tolerate Variable Shadowing"

Does anybody know why this code does not produce errors in JSHint?
I think it should give me a variable shadowing warning but I'm not getting one.
I have "Tolerate Variable shadowing" as false am using the visual studio plugin.
RES.test = function () {
var test, f;
f = function () {
var test;
window.alert(test);
};
};
Thanks.
I just stumbled onto this too. Apparently JSHint developers' definition of "shadowing" is not what you expect. For them, hiding a variable name coming from a closure is not shadowing. And yes, I find it strange too :-)
If you look at their test suite, they mean something like "redefinition", where you do
var a = 1;
...
var a = 2;
look at their test case: https://github.com/jshint/jshint/blob/master/tests/stable/unit/fixtures/redef.js

Flex: Why can't I get sub-children of display object?

I am having problems accessing sub-children of my displayObject. Here is my code:private
function resizeTag(event:MouseEvent):void{
var currTagPos:Number = 1;
var theTagBox:DisplayObject = tagCanvas.getChildAt(currTagPos); //i have confirmed that it exists on the stage and has sub-children
trace(theTagBox.getChildAt(0).width);
}
Essentially I'm trying to get:
tagCanvas.getChildAt(currTagPos).getChildAt(0).width;
but it's not working. Thanks for any guidance you can provide :)
Looks like I needed to call it as a DisplayObjectContainer. I did this instead:
trace((tagCanvas.getChildByName(currTagName) as Canvas).getChildAt(3) as Button);
I found this post which helped me figure it out:
http://www.nabble.com/undefined-method-getChildAt-td19812715.html

Resources