I've tried 2 different ways to setup an observer/observable to make this code work:
Setup #1:
var xObserver;
var xObservable = Rx.Observable
.create(observer => xObserver = observer)
.publish()
.refCount();
Setup #2:
var xObserver = Rx.Subject.create();
var xObservable = x;
Usage
xObserver.next('foo'); // no subscription yet, so nothing should happen
xObservable.subscribe(v => console.log(v)); // pipe values to console
xObserver.next('bar'); // push another value, should go to console
My expectation is for nothing to happen when "foo" is pushed to the observer, and for only "bar" to be shown on the console.
With "Setup #1" I get an error "TypeError: Cannot read property 'next' of undefined" which makes sense because no observer has subscribed yet so the xObserver is not initialized yet.
With "Setup #2" I get an error "TypeError: xObserver.next is not a function".
What am I doing wrong?
Use:
let xObs = new Rx.Subject();
When you use .create you have to supply an Observer, see the docs for details.
Another pitfall might be the version, in version < 5 there is only .onNext():
xObs.onNext("myData");
https://jsfiddle.net/mzkmuewf/
In version > 5, there is only .next():
xObs.next("myData");
https://jsfiddle.net/j1sksg7q/
Related
I added conversion and revenue columns to the script which can be found here.
This is the error I'm getting in the logs (the spreadsheet is updating fine with no issues):
TypeError: newValue.indexOf is not a function
at formatChangeString (Code:366:33)
at emailRow (Code:314:11)
at Code:285:15
at Array.forEach (<anonymous>)
at sendEmail (Code:284:17)
at main (Code:106:7)
formatChangeString(newValue,oldValue) expects newValue to be a string (so that newValue.indexOf('%') can be called.
It seems that one of the metrics you added is returned by the AdsApp.report call as a different type (most likely Number).
If you want a quick workaround, just change the line
const isPercentage = newValue.indexOf('%') >= 0;
to
const isPercentage = String(newValue).indexOf('%') >= 0;
Im trying create and sign a raw transaction with bitcoinjs-lib.
const assert = require('assert');
const ecpair = require('ecpair');
const bitcoin = require('bitcoinjs-lib');
var keys =new bitcoin.ecpair.fromWIF('cMvPQZiG5mLARSjxbBwMxKwzhTHaxgpTsXB6ymx7SGAeYUqF8HAT', bitcoin.networks.testnet);
this is my code and i get error "Cannot read property 'fromWIF' of undefined error" message.
i think i am making a mistake while adding the libraries.
bitcoinjs-lib version is 6 and using nodejs.
thank you.
I am listenig for MessageSentEvent
window.Echo.private("chat" + this.chat.id).listen(
"MessageSentEvent",
e => {
var date = new Date().getTime();
this.lastMessageDate = moment().to(date);
this.lastMessage = e.message;
console.log(e.message.sender.id, this.loggedInUser.id);
// if (e.message.sender.id !== this.loggedInUser.id)
this.chat.messages.push(e.message);
}
);
while I am using the toOthers-method in my controller
broadcast(
new MessageSentEvent(new MessageResource($message), $authUser)
)->toOthers();
leading to duplicates for the one who sent the message
duplicates for the sender
while the receiver just get the expected 1 message
receiver as expected 1 message
if using the outcommented condition, it works fine.... but too me it does not feel clean.
I must have made a mistake somewhere. Why does the toOthers()-method not work and I need to write a condition?
Thx:)
On your axios config try to add your connection socket id.
Try this if You use Echo and if You use pusher or any socket library run the function that return a scketId :
window.axios.defaults.headers.common['X-Socket-Id'] = window.Echo.socketId();
When obtaining all channels to send a message to all, the bot ignores the command. Here's my code.
async def lockdown(ctx):
allchannels = bot.get_all_channels()
overwrite = channel.overwrites_for(ctx.guild.default_role)
locked = overwrite.send_messages = False
await locked.send(allchannels, 'This server has been locked down.')
Try printing allchannel, you'll see where you did an error.
You can't use bot.get_all_channels() in this way that's all
I am having an issue with the IONotificationCreatePort function in IOKit:
var NotificationPort = IONotificationPortCreate(MasterPort)
IONotificationPortSetDispatchQueue(NotificationPort, DispatchQueue)
gives the following compiler error when NotificationPort is used in the function call in the second line
'Unmanaged IONotificationPort' is not identical to
'IONotificationPort'
if I use the following code based on the information in the Using Swift with Cocoa and Objective-C document, it compiles but generates a runtime error
var NotificationPort = IONotificationPortCreate(MasterPort).takeRetainedValue()
IONotificationPortSetDispatchQueue(NotificationPort, DispatchQueue)
Thread 1: EXC_BAD_ACCESS(code=1, address=0xwhatever)
So I think I have the run time error figured out, the IONotificationPort object does not have takeRetainedValue method
The crux of the problem as I see it, is that the IONotificationPortCreate function creates an IONotificationPort object and returns the reference to it.
I have looked all over the place and there is lots of information about and ways to pass references into a function call from Swift but nowhere can I find how to deal with references as a return value.
Can Swift call an object by reference?
Or am I way off the mark here????
Here is the objective C code that I am trying to convert to swift:
_notificationPort = IONotificationPortCreate(masterPort);
IONotificationPortSetDispatchQueue(_notificationPort, _controllerQueue);
Here is the complete code snippet from my swift file:
//Get IOKit Master Port
var MasterPort: mach_port_t = 0
let BootstrapPort: mach_port_t = 0
var MasterPortReturnCode: kern_return_t = 0
MasterPortReturnCode = IOMasterPort(BootstrapPort, &MasterPort)
println("Master port returned as \(MasterPort) with return code of \(MasterPortReturnCode)")
//Set up notification port and send queue
let DispatchQueue = dispatch_queue_create("com.apparata.AVB_Browser", DISPATCH_QUEUE_SERIAL)
var NotificationPort = IONotificationPortCreate(MasterPort)
IONotificationPortSetDispatchQueue(NotificationPort, DispatchQueue)