Creating an Observable for Mock Data in Angular 2 - promise

I am trying to return an Observable from a service with mock data.
I am returning this from my service :
return Observable.of(new Object()).map(MOCKACCOUNT =>JSON.stringify(MOCKACCOUNT));
I get an error
Observable_1.Observable.of is not a function.
Am I missing some include? I am importing
import {Observable} from "rxjs/Observable";
Note: I was returning a mock promise prior but based on my understanding I would not be able to interpolate the value. For example {{returnFromServiceStoredInExportedClass.name}}

Looks like
import {Observable} from "rxjs/Observable";
should be
import {Observable} from "rxjs/Rx";
See also Angular2 RxJS getting 'Observable_1.Observable.fromEvent is not a function' error

Use
return Observable.of(new Object()).mapTo(MOCKDATA);`
The import statement is fine.
import {Observable} from "rxjs/Observable";
Also need to import the ts file for MOCKDATA
import {MOCKDATA} from "../path_to_mockdata";

Should be
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of';
because
import {Observable} from "rxjs/Rx";
will import all other operators that you don't need

Related

Problems with SelectMenu discord.py

I'm trying to make SelectMenu to give out roles on the server I need to make it infinite, but I don't understand how. And besides, the one I wrote does not give out roles. I already third day sit with this error, and do not understand what is wrong. Bot does not even show what the error, the console is empty. here is the code. What do I have to do to make it work as intended?
#client.command()
async def sm(inter):
view =None
if inter.author.id == 1012357055987851345:
await inter.send('Text',
components = [
Select(
placeholder = 'Выберете роль',
options = [
SelectOption(label="Роль", value="Девушка"),
SelectOption(label="Роль2", value="Rainbow"),
])])
interaction = await client.wait_for("select_option")
selected = interaction.values[0]
if selected == "Роль":
user = inter.author
role = client.get_role(1029824401878810624)
await inter.user.add_roles(role)
await inter.send("Роли выданы")
if selected == "Роль2":
await user.add_roles(role)
await inter.send("Роли выданы")
And if you can, show me the working version as an example.
imports:
from msilib.schema import Component
from optparse import Option
import discord
from discord.ui import Select, View
import json
import os
import random
import asyncio
import aiohttp
from discord.ext import commands
from dislash import slash_commands
from discord_slash import SlashCommand
from discord_slash import SlashContext
import discord_components
from discord_components import DiscordComponents, Select, SelectOption, Button, ButtonStyle
from discord_components import *
maybe you can use discord.py2, it worked for me

Laravel-FullCalendar-Scheduler using npm i fullcalendar-scheduler

https://github.com/JMackCo/Laravel-FullCalendar-Scheduler
public working repo commented with TODO
I have tried to use the npm i fullcalendar-scheduler.
I would like to be able to use the single package instead of
all the individual packages. I have searched and tried with
no success
I would like to replace this with the single fullcalendar-scheduler:
//JV TODO fullcalendar-scheduler
import { Calendar } from '#fullcalendar/core';
import interactionPlugin from '#fullcalendar/interaction';
import dayGridPlugin from '#fullcalendar/daygrid';
import timeGridPlugin from '#fullcalendar/timegrid';
import listPlugin from '#fullcalendar/list';
import adaptivePlugin from '#fullcalendar/adaptive';
import resourceTimeGridPlugin from '#fullcalendar/resource-timegrid';
import resourceTimelinePlugin from '#fullcalendar/resource-timeline';
import googleCalendarPlugin from '#fullcalendar/google-calendar';

Where is RxJS 6 static merge?

In RxJS 6, how do I import a static merge function for merging a list of Observables?
I want to be able to do:
const merged$ = merge(
obs1$,
obs2$,
obs3$
);
I've tried:
import { merge } from 'rxjs/observable/merge'; and
import { merge } from 'rxjs/operators';
but neither seems to give me what I want.
Importing has been made easy in RxJS 6:
import { merge } from 'rxjs';
You may want to read the official migration guide.
Another useful resource regarding importing in RxJS 6 is this talk by Ben Lesh who is the RxJS lead.
RxJS 7.X
In RxJS v7.X the merge() method is depricated and will be removed un RxJs v8.X, use mergeWith() instead.
See:
https://rxjs.dev/api/operators/mergeWith
https://rxjs.dev/api/operators/merge (depricated)
import { fromEvent } from 'rxjs';
import { map, mergeWith } from 'rxjs/operators';
const clicks$ = fromEvent(document, 'click').pipe(map(() => 'click'));
const mousemoves$ = fromEvent(document, 'mousemove').pipe(map(() => 'mousemove'));
const dblclicks$ = fromEvent(document, 'dblclick').pipe(map(() => 'dblclick'));
mousemoves$.pipe(
mergeWith(clicks$, dblclicks$),
)
.subscribe(x => console.log(x));
// result (assuming user interactions)
// "mousemove"
// "mousemove"
// "mousemove"
// "click"
// "click"
// "dblclick"
(example from api docs)
I believe now when the "creation" classes were removed the recommended way is importing directly from 'rxjs':
import { merge as mergeStatic } from 'rxjs';
Previous alpha version of RxJS 6 used to have 'rxjs/create' file but this has been removed already: https://github.com/ReactiveX/rxjs/blob/master/CHANGELOG.md#600-alpha3-2018-02-06
However this expects you to use path maps correctly otherwise you'll import a lot of things you don't need. If you don't use path maps or the build process hidden from you you can import directly the correct file:
import { merge as mergeStatic } from 'rxjs/internal/observable/merge';
As of RXJS 6. The merge is in the rxjs/operators
import { map, take, merge, switchMap, filter } from 'rxjs/operators';

How to access a struct from an external package in Go

I'm trying to import a struct from another package in the following file:
// main.go
import "path/to/models/product"
product = Product{Name: "Shoes"}
// models/product.go
type Product struct{
Name string
}
But in the main.go file the struct Product is undefined. How do I import the struct?
In Go you import "complete" packages, not functions or types from packages.
(See this related question for more details: What's C++'s `using` equivalent in golang)
See Spec: Import declarations for syntax and deeper explanation of the import keyword and import declarations.
Once you import a package, you may refer to its exported identifiers with qualified identifiers which has the form: packageName.Identifier.
So your example could look like this:
import "path/to/models/product"
import "fmt"
func main() {
p := product.Product{Name: "Shoes"}
// Use product, e.g. print it:
fmt.Println(p) // This requires `import "fmt"`
}

Call a method of a web component and respond to events

I'm working on a Dart project where I have created a custom element with the Web_ui package that has some animation. What I was hoping to do is to have within the dart code for the element something like this....
class MyElement extends WebComponent {
...
void StartAnimation() { ... }
...
}
and then in the main() function of the dart app itself I have something like this...
void main() {
MyElement elm = new MyElement();
elm.StartAnimation(); // Kicks off the animation
}
The Dart editor tells me that Directly constructing a web component is not currently supported. It then says to use WebComponent.forElement -- but I'm not clear on how to use that to achieve my goal.
While you can't yet import web components into a Dart file, you can access them via query() and .xtag. xtag gives you a reference the web component instance that the element is associated with. You do have to be careful that you allow the Web UI setup to complete so that xtag is given a value.
Here's an example:
import 'dart:async';
import 'dart:html';
import 'package:web_ui/web_ui.dart';
main() {
Timer.run(() {
var myElement = query('#my-element').xtag;
myElement.startAnimation();
});
}
This will get better with the ability to import components, directly subclass Element and maybe some lifecycle events that guarantee that you get the correct class back from a query(). This is what the exemple should look like in the future:
import 'dart:async';
import 'dart:html';
import 'package:web_ui/web_ui.dart';
import 'package:my_app/my_element.dart';
main() {
MyElement myElement = query('#my-element');
myElement.startAnimation();
}

Resources