Flux TypeError: Class constructor AccessManagement cannot be invoked without 'new' - reactjs-flux

I installed React Flux. I am getting the following error:
TypeError: Class constructor AccessManagement cannot be invoked without 'new'
What needs to be instanciated? This is my class.
class Reports extends React.Component {
constructor(props) {
super(props);
}
static getStores() {
return [ReportsStore];
}
static calculateState(prevState, props) {
const rep = ReportsStore.getState();
return {
isLoading: rep.isLoading,
reportRequests: rep.ReportRequests
};
}
render() {
return (<dvi></div>
);
}
componentDidMount() {
}
}
export default Container.create(Reports);
The flux version is: "flux": "^3.1.3",
Any idea how to solve this?

Related

Xamarin.Forms implementation of Facebook Audience Network

I'm struggling with implementation of Facebook Audience Network in my Xamarin.Forms app.
Available nuget package is old and has obsolete metods.
I was able to implement ads by my own, test interstital ads are displaying correctly, but when other users are using my app ads are not displayed at all. I see in logs that FAN returned error code 1001 with "No fill" message.
What have I done:
added to solution new Android class parse project. Project contains 'AudienceNetwork.aar` file from facebok page. Build action set to LibraryProjectZip
I had to add some classes to fix build errors:
public partial class AdView
{
internal partial class IAdViewLoadConfigBuilderInvoker
{
IAdLoadAdConfig IAdLoadConfigBuilder.Build()
{
return Build();
}
IAdLoadConfigBuilder IAdLoadConfigBuilder.WithBid(string p0)
{
return WithBid(p0);
}
}
}
public partial class InterstitialAd
{
IAdLoadConfigBuilder IFullScreenAd.BuildLoadAdConfig()
{
return BuildLoadAdConfig();
}
IFullScreenAdShowConfigBuilder IFullScreenAd.BuildShowAdConfig()
{
return BuildShowAdConfig();
}
internal partial class IInterstitialAdLoadConfigBuilderInvoker
{
IAdLoadAdConfig IAdLoadConfigBuilder.Build()
{
return Build();
}
IAdLoadConfigBuilder IAdLoadConfigBuilder.WithBid(string p0)
{
return WithBid(p0);
}
}
internal partial class IInterstitialAdShowConfigBuilderInvoker
{
IFullScreenAdShowAdConfig IFullScreenAdShowConfigBuilder.Build()
{
return Build();
}
}
}
public abstract partial class NativeAdBase
{
internal partial class INativeAdLoadConfigBuilderInvoker
{
IAdLoadAdConfig IAdLoadConfigBuilder.Build()
{
return Build();
}
IAdLoadConfigBuilder IAdLoadConfigBuilder.WithBid(string p0)
{
return WithBid(p0);
}
}
}
public partial class RewardedVideoAd
{
IAdLoadConfigBuilder IFullScreenAd.BuildLoadAdConfig()
{
return BuildLoadAdConfig();
}
IFullScreenAdShowConfigBuilder IFullScreenAd.BuildShowAdConfig()
{
return BuildShowAdConfig();
}
internal partial class IRewardedVideoAdLoadConfigBuilderInvoker
{
IAdLoadAdConfig IAdLoadConfigBuilder.Build()
{
return Build();
}
IAdLoadConfigBuilder IAdLoadConfigBuilder.WithBid(string p0)
{
return WithBid(p0);
}
}
internal partial class IRewardedVideoAdShowConfigBuilderInvoker
{
IFullScreenAdShowAdConfig IFullScreenAdShowConfigBuilder.Build()
{
return Build();
}
}
}
public abstract partial class AdComponentFrameLayout
{
public void SetLayoutParams(ViewGroup.LayoutParams p0)
{
SetLayoutParams(p0);
}
}
public abstract partial class AdNativeComponentView
{
public void SetLayoutParams(ViewGroup.LayoutParams p0)
{
SetLayoutParams(p0);
}
}
internal partial class IInterstitialAdApiInvoker
{
IAdLoadConfigBuilder IFullScreenAd.BuildLoadAdConfig()
{
return BuildLoadAdConfig();
}
IFullScreenAdShowConfigBuilder IFullScreenAd.BuildShowAdConfig()
{
return BuildShowAdConfig();
}
}
public partial class InitSettingsBuilder
{
AudienceNetworkAds.IInitSettingsBuilder AudienceNetworkAds.IInitSettingsBuilder.WithInitListener(AudienceNetworkAds.IInitListener p0)
{
return WithInitListener(p0);
}
AudienceNetworkAds.IInitSettingsBuilder AudienceNetworkAds.IInitSettingsBuilder.WithMediationService(string p0)
{
return WithMediationService(p0);
}
AudienceNetworkAds.IInitSettingsBuilder AudienceNetworkAds.IInitSettingsBuilder.WithPlacementIds(IList<string> p0)
{
return WithPlacementIds(p0);
}
}
internal partial class IRewardedVideoAdApiInvoker
{
IAdLoadConfigBuilder IFullScreenAd.BuildLoadAdConfig()
{
return BuildLoadAdConfig();
}
IFullScreenAdShowConfigBuilder IFullScreenAd.BuildShowAdConfig()
{
return BuildShowAdConfig();
}
}
in Android project in MainActivity:
AudienceNetworkAds.Initialize(this);
InterstitialAdsRenderer
public class InterstitalAdsRenderer : IInterstitalAdsService
{
InterstitialAd _interstitial;
public void Show(string adsId)
{
//AdSettings.AddTestDevice("fe9823bf-946e-4a43-b38c-f958d0bfaa31");
_interstitial = new InterstitialAd(Application.Context, adsId);
var loadAdConfig = _interstitial.BuildLoadAdConfig()
.WithAdListener(new InterstitialAdListener(_interstitial))
.Build();
_interstitial.LoadAd(loadAdConfig);
}
}
internal class InterstitialAdListener : Java.Lang.Object, IInterstitialAdListener
{
private readonly InterstitialAd _interstitial;
public InterstitialAdListener(InterstitialAd interstitial)
{
}
public void OnAdClicked(IAd p0)
{
}
public void OnAdLoaded(IAd p0)
{
_interstitial.Show();
}
public void OnError(IAd p0, AdError p1)
{
Console.WriteLine("OnError: " + p1.ErrorMessage);
}
public void OnLoggingImpression(IAd p0)
{
}
public void OnInterstitialDismissed(IAd p0)
{
}
public void OnInterstitialDisplayed(IAd p0)
{
}
}
As I said earlier test ads in test device(emulator added to testsDevices) is displaying ads correctly, but on the production there is no ads :/
Anyone had implemented facebok ads in Xamarin.Forms project and can tell me how can I do this correctly?
this error normally means that you have not logged in to Facebook app or Facebook app is not available in the device that you are running your app

Method addObserver must be called on the main thread Exception, While inserting data to room database

I am trying to insert data into the room database using the kotlin coroutine. But I always get an exception java.lang.IllegalStateException: Method addObserver must be called on the main thread
But I don't have an observer in this code, the insert call is called from launch with Dispatchers IO
DocumentDao.kt
#Dao
interface DocumentDao {
#Insert
suspend fun insertDocument(document: Document): Long
}
Repository.kt
class Repository#Inject constructor(val db: MyDB) {
suspend fun demoInsert(
uri: String,
albumId: Long
): Long {
val newDoc = Document(0, albumId, rawUri = uri)
return db.documentDao().insertDocument(newDoc)
}
}
MyViewModel.kt
#HiltViewModel
class MyViewModel#Inject constructor(val repo: Repository) : ViewModel() {
suspend fun demoInsert(
uri: String,
albumId: Long
): Long {
return repo.demoInsert(uri, albumId)
}
}
MyFrag.kt
#AndroidEntryPoint
class MyFrag: Fragment() {
val viewModel: MyViewModel by viewModels()
....
....
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.insert.setOnClickListener {
lifecycleScope.launch(Dispatchers.IO) {
val res = viewModel.demoInsert("test", Random.nextLong(500))
Log.d(TAG, "onViewCreated: $res")
}
}
........
.......
}
}
what is wrong with this code? please help me
I'm not sure about this but you can launch coroutine inside listener with Main Dispatcher and later use withContext inside DB function, to change context.
I was facing the same issue and I solved yhis way :
private fun insertAllItemsInDb(data : List<PostResponse>){
val listPost = data.map { it.toUI() }
val scope = CoroutineScope(Job() + Dispatchers.Main)
scope.launch {
localViewModel.insertAllPosts(listPost)
}
}
ViewModel:
fun insertAllPosts(posts: List<PostItem>) {
viewModelScope.launch {
dbRepository.insertAllPosts(posts)
}
}
Creating view model with:
val viewModel: MyViewModel by viewModels()
Will result in lazy creating. Creation of real object will be performed when you access your object for first time. This happens inside:
lifecycleScope.launch(Dispatchers.IO) {
val res = viewModel.demoInsert("test", Random.nextLong(500))
Log.d(TAG, "onViewCreated: $res")
}
And since implementation of method viewModels<>() looks like this:
#MainThread
public inline fun <reified VM : ViewModel> Fragment.viewModels(
noinline ownerProducer: () -> ViewModelStoreOwner = { this },
noinline factoryProducer: (() -> Factory)? = null
): Lazy<VM> = createViewModelLazy(VM::class, { ownerProducer().viewModelStore }, factoryProducer)
You are getting
Method addObserver must be called on the main thread
You should be able to fix this with something like this.
lifecycleScope.launch(Dispatchers.IO) {
val res = withContext(Dispatchers.Main + lifecycleScope.coroutineContext){}.demoInsert("test", Random.nextLong(500))
Log.d(TAG, "onViewCreated: $res")
}
MyViewModel.kt
#HiltViewModel
class MyViewModel#Inject constructor(val repo: Repository) : ViewModel() {
suspend fun demoInsert(
uri: String,
albumId: Long
): Long {
viewModelScope.launch {
repo.demoInsert(uri, albumId)
}
}
}
MyFrag.kt
#AndroidEntryPoint
class MyFrag: Fragment() {
val viewModel: MyViewModel by viewModels()
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.insert.setOnClickListener {
lifecycleScope.launch(Dispatchers.Main) {
viewModel.demoInsert("test", Random.nextLong(500))
}
}
}
}

Wiring an Observable to a SingleInterop in Vert.x

I'm having trouble figuring out how to correctly wire in an Observables onNext() call with a SingleInterop. I'm also not sure how to return the expected result without blocking the main thread. My rough attempt is shown below. Any help would be appreciated.
public class SomeClass {
private ExecutorService executor = Executors.newSingleThreadExecutor;
private ObservableOnSubscribe<MyCustomObj> disHandler;
public SomeClass() {
init();
}
/** Create an observable to listen to a data input stream **/
private void init() {
disHandler = emitter ->
executor.submit(() -> {
try {
while (true) {
MyCustomObj mco = readFromDataInputStream();
emitter.onNext(mco);
}
// Should never complete since always listening...
emitter.onComplete();
}
catch(Exception e) {
emitter.onError(e);
}
});
}
public Single<String> invokeSomethingAndGetResponseFromHandler(Object someObj) {
// Eventually the disHandler will send an onNext() as
// a result of doSomethingToBackend() call.
Observable<String> observer = Observable.fromCallable(doSomethingToBackend(someObj));
observer.subscribe(item -> item);
return ???.to(SingleInterop.get());
}
}
public class GraphQLVertx {
public VertxDataFetcher<Single<String>> dataFetcherTest() {
return new VertxDataFetcher<>((env, future) -> {
try {
future.complete(someClass.invokeSomethingAndGetResponseFromHandler("Blah");
}
catch(Exception e) {
future.fail();
}
});
}
}
The observable has a helper method that returns the first emitted element as a single, or an error, so if you already have an Observable<String> you can transform it to Single<String> like this:
public Single<String> invokeSomethingAndGetResponseFromHandler(Object someObj) {
return Observable.fromCallable(doSomethingToBackend(someObj))
.singleOrError();
}

MassTransit Bus.Publish calls SendObserver

I have noticed that when i call Bus.Publish my SendObserver is beeing called along with my PublishObserver. In my original scenario i use the observers for some debug logging where i noticed that when i call Publish both the PublishObserver and the SendObserver is called with the same message. The example code below reproduces the scenario:
public class YourMessage { public string Text { get; set; } }
public class SendObserver : ISendObserver {
public Task PreSend<T>(SendContext<T> context) where T : class
{
return Task.CompletedTask;
}
public Task PostSend<T>(SendContext<T> context) where T : class
{
Console.Out.WriteLineAsync($"Message Sent, Id: {context.MessageId}");
return Task.CompletedTask;
}
public Task SendFault<T>(SendContext<T> context, Exception exception) where T : class
{
return Task.CompletedTask;
}
}
public class PublishObserver : IPublishObserver
{
public Task PrePublish<T>(PublishContext<T> context) where T : class
{
return Task.CompletedTask;
}
public Task PostPublish<T>(PublishContext<T> context) where T : class
{
Console.Out.WriteLineAsync($"Message Published, Id: {context.MessageId}");
return Task.CompletedTask;
}
public Task PublishFault<T>(PublishContext<T> context, Exception exception) where T : class
{
return Task.CompletedTask;
}
}
public class Program
{
public static void Main()
{
var bus = Bus.Factory.CreateUsingRabbitMq(sbc =>
{
var host = sbc.Host(new Uri("rabbitmq://rabbitmq/PublishSendTest"), h =>
{
h.Username("guest");
h.Password("guest");
});
sbc.ReceiveEndpoint(host, "test_queue", ep =>
{
ep.Handler<YourMessage>(context =>
{
return Console.Out.WriteLineAsync($"Received: {context.Message.Text}");
});
});
});
bus.ConnectSendObserver(new SendObserver());
bus.ConnectPublishObserver(new PublishObserver());
bus.Start();
bus.Publish(new YourMessage { Text = "Hi" });
Console.WriteLine("Press any key to exit");
Console.ReadKey();
bus.Stop();
}
}
Output:
Press any key to exit
Message Sent, Id: ac4f0000-3051-1065-bbe5-08d6335c9e05
Message Published, Id: ac4f0000-3051-1065-bbe5-08d6335c9e05
Received: Hi
Is this the expected behaviour? If so what can i do to determine if it acutally was a Publish call that created the message?
I used version 5.1.5
The inconsistent observer issue should be resolved in the develop builds, and a test has been created to verify the behavior on the supported transports. Once released, the send observer should only be called on an actual Send, and the publish observer should only be called on an actual Publish.
Thanks for bringing this up, I'm not sure how it got out of whack.

Passing ajax request data from my service to a component (Angular 4)

I have a service that retrieves data from a GET request and stores this data into two variables that I want to pass to my component - I can see all the data within the service I am just unable to retrieve this data once in my component.
When I call this.sidebarService.getMenuItems() in the console.log() it returns undefined - any ideas
// sidebar service
import { Injectable } from '#angular/core';
import { HttpClient, HttpParams } from '#angular/common/http';
import { UserService } from '../../services/user.service';
#Injectable()
export class SidebarService {
menu: any;
menuItems: any;
menuCategories: any;
constructor(private http: HttpClient, private userService: UserService) {
getMenuItems() {
if (this.userService.getAuth() != null) {
this.http.get('https://dev.mysite.com/api/calendar/auth',
{ params: new HttpParams()
.set('token', this.userService.getAuth().__token)})
.subscribe(data => {
console.log('data', data);
if (data !== undefined) {
this.menuItems = (data.menuItems !== undefined) ? data.menuItems : [];
this.menuCategories = (data.menuCategories !== undefined) ? data.menuCategories : [];
}
});
}
}
}
// sidebar component
import { Component, OnInit } from '#angular/core';
import { HttpClient, HttpParams } from '#angular/common/http';
import { UserService } from '../../services/user.service';
import { SidebarService } from './sidebar.service';
#Component({
selector: 'app-sidebar',
templateUrl: './sidebar.component.html',
styleUrls: ['./sidebar.component.scss'],
})
export class SidebarComponent implements OnInit {
menu: any;
menuItems: any;
menuCategories: any;
constructor(private http: HttpClient, private userService: UserService, private sidebarService: SidebarService) {
console.log('menuService', this.sidebarService.getMenuItems());
}
ngOnInit() {
}
objectKeys = function(obj) {
return Object.keys(obj);
}
}
You are not returning anything from thegetMenuItems() method
You should return an Observable :
...
return this.http.get('...

Resources