How to use mapGetters when Vue CDN is used? - node.js

I'm trying to use mapGetters from Vue.js but instead use NPM to install I used Vue CDN like this:
<script src="https://unpkg.com/vuex#3.0.1/dist/vuex.js"></script>
I can't do the import as usual:
import {mapGetters} from 'vuex';
And neither use mapGetters without import.
export default {
computed: mapGetters([
'doubleCounter',
'realCounter'
])}
How can I use mapGetters using Vue CDN?

export default {
computed: Vuex.mapGetters([
'doubleCounter',
'realCounter'
])
}
export default {
computed: {
...Vuex.mapGetters([
'doubleCounter',
'realCounter'
]),
otherComputedProperty () {
// implementation
}
}
}

I had run into this exact issue and this answer was perfect. The reason I replying is because in google searches you are unlikely to find this unless you include CDN in your search. With that included it is a top result as it should be. I hope others will find this in the future if they are looking for solutions when they are searching for how to use mapGetters or mapState or mapActions or mapMutations and they add the line
import { mapMutations } from 'vuex'
only to get the error in the console
Uncaught SyntaxError: Cannot use import statement outside a module
I think the answer would be fairly obvious to someone familiar with including via CND instead of via NPM, but for a relatively new cut-and-paste jockey, like myself, I was struggling to solve this problem. I didn't even think to include cdn in my google search. Only after asking in a different forum did someone suggest this post and/or including it in the search did I find this easy and clear solution.
Hopefully by posting this, the indexing will eventually include this in some of the searches I did without cdn, for the next explorer.

Related

how can i create influxdb with nestjs?

i am a new software developer. I don't have much software background, but I'm trying to learn as much as I can. Is there anyone who has done influxdb operation with nestjs before? If yes, can you share your previous experiences?
Thank you in advance for reading and replying.
Your going to face many hardships if you consider using nestjs... Maybe im wrong and your underselling yourself, but if you are asking if its possible to connect a database to your backend then nest is surly going to be WAYYYYY WAYYYYY WAYYYYY to complex -> to be able to figure stuff out... Not that you CANT but you might want to consider
Express first just to get an understanding of how a backend works -> without having to plan out all your dtos' controllers services yatta yatta yatta.. you can do all of the same stuff with express, infact the developers used express to make next -> and then added a whole lot of enterprise level stuff that doesnt come standard with express.
plus if you are new to coding then typescript might be a bit much. very sorry if this was not what you were looking for Im not trying to steer you in any particular direction. but I spend 12 hours - 36 hours sometimes trying to figure things out that I already had working before ... the injection and all that come with nest is good , but if you dont know why you need it , then its going to be very hard to actually learn the concepts.
its alot easier to teach someone how to drink water if theyre thirsty .
otherwise you are just going to spend alot of time that could of went into learning the things that are a prerequisite of nest
strong es6 / ts is def a must
the es6 part is more important imo because dealing with everything async for instance and the way everything is formatted its very confusing without a strong grasp of whats going on behind the scenes.
--- as im sure your going to want to find out the hard way -> and i dont blame you if you can get through it you will be a much stronger person =) but here try this on for size.
https://www.npmjs.com/package/nest-influxdb
import { Module } from "#nestjs/common";
import { InfluxDbModule, InfluxModuleOptions } from "nest-influxdb";
import { UtilsModule } from "./utils/utils.module";
import { ConfigService } from "./utils/config/config.service";
#Module({
imports: [
InfluxDbModule.forRootAsync({
imports: [UtilsModule],
inject: [ConfigService],
useFactory: async (
config_servie: ConfigService
): Promise<InfluxModuleOptions> => {
return {
host: config_servie.get("INFLUX_HOST")
};
}
}),
BlogModule
],
controllers: [AppController],
providers: [AppService]
})
export class AppModule {}
this will go in your root level module file -> then you will use the for feature method for the specific thing inside your root database
check the nest docs for how it works with other databases then try to connect the dots with that above package

Typescript imports destroys lookup?

I am trying to use a nodejs library like uuid in my typescript app. This simple import works just fine if I want to only use it in a specific class:
import { v4 } from "uuid";
class MyClass {
...
}
However, this makes the class MyClass not "discoverable" by any other files in my solution. Sure I could export it, but that forces me to import the class in every usage, and the problem spreads like a cancer to every file. Do I really have to import/export every single class/file in my application just because I want to produce a simple UUID?
I saw that I can use require instead, however typescript doesn't know what that keyword is. I found this question but neither installing #types/node nor the quick and dirty declare var require any works.
It really seems like I am jumping through a lot of unnecessary hoops just to generate a uuid in typescript. Am I doing something very wrong?
Thanks

typescript replaceent for require inside a function in nodejs

I trying to convert a nodejs project to TypeScript and while mostly I did not faced really difficult obstacles during this process, the codebase has few gotchas like this, mostly in startup code:
function prepareConfiguration() {
let cloudConfigLoader = require('../utils/cloud-config');
return cloudConfigLoader.ensureForFreshConfig().then(function() {
//do some stuff
});
}
I may be need just an advice on which approach for refactoring this has less code changes to be made to make it work in TypeScript fashion.
In response to comments, more details:
That require loads the node module, not a JSON file. From that module the ensureForFreshConfig function contacts with a cloud service to load a list of values to rebuild a configuration state object.
Problem is that mdule was made in standard node approach of "module is isngleton object" and its independencies include auth component that will be ready only when the shown require call is made. I know it is not best a way to do so..
Typesript does not allow "mport that module later" except with dynamyc import which is problematic as mentiond in comment.
The "good" approach is to refactor that part of startup and make the ensureForFreshConfig and its dependency to initiate its ntenras on demand via cnstructors.. I just hoped ofr some soluiton to reduce things to be remade durng this transition to the TypeScript
import { cloudConfigLoader } from '../utils/cloud-config'
async function prepareConfiguration() {
await cloudConfigLoader.ensureForFreshConfig()
// do some stuff
// return some-stuff
}
The function is to be used as follows.
await prepareConfiguration()

ts-node import not defined at runtime

I have the following reference import { STORE } from "../data/store"; It's part of a react project and works as expected.
However I need to run some code separately over STORE and accessed it the same way as it is in the react project, but ran via ts-node. When I try to access STORE by let data = STORE[videoId].labels;, with videoId set as "home" I get TypeError: Cannot read property 'home' of undefined.
Might anyone know what I'm missing --- must be something specific to ts-node...? Thanks!
In case someone arrives on this page because of imports issue, like I did, here's what my problem was:
I had three files : index.ts, File.json and File.ts
In index.ts:
import { thing } from "./File";
was working well in VS Code: I had auto-completion for thing and everything.
But when running ts-node index.ts, thing was undefined!
When I remembered that I had the json file, I just renamed File.ts to File.module.ts and changed the import to:
import { thing } from "./File.module";
and it was sorted.
It sounds like the property STORE is undefined..
If you change import { STORE } from "../data/store"; to import * as STORE from "../data/store" does it work?

how can I import json file in typescript

I am using typescript and requirejs. For the most part the amd modules are generated beautifully. I am however stuck with loading using requirejs json or for that matter text plugin.
define(["json!sometextfile.json"], function(myJson)
How can I do this in typescript. I am using TS 1.6 at the moment.
I'm not sure I have understood your question, but I think you want to know how to call require directly without getting a compiler error... for example:
require(["json!sometextfile.json"], function(myJson) {
});
The quick fix for this is to supply a very open definition for the require function:
declare var require: any;
require(["json!sometextfile.json"], function(myJson) {
});
You can improve upon this crude fix by using the full RequireJS type definition from the Definitely Typed project.

Resources