« first day (4735 days earlier)      last day (437 days later) » 

05:15
HI guys
05:39
I am trying to map inside array of Object in React JS. I have three layers of depth. It was easy to render them using map function for 2 layers but could not figure why can't i map inside third layer. codesandbox.io/s/map-nested-array-obj-t5dvlk?file=/src/App.js
I have mention my code block in the above link
06:04
NO worries guys I got it. Don't worry about the above problem
 
1 hour later…
07:23
Hi All,
Im using below PlugIn for Google Auth and Youtube login
https://github.com/CodetrixStudio/CapacitorGoogleAuth
I have two functionalities,
1. Social SignIn using Google
2. Connecting with Youtube to get accessToken (Post Login functionality)
The problem im facing is, once I have GoogleAuth.initialize() and assigned the scopes, then Im not able to update the scopes
As while connecting with Youtube inside the application login, I need to pass more scopes whereas while Google SSO, I need to pass only basic scopes
Is there any way I can override / reassign the scope. Or reinitialize the entire Auth
 
5 hours later…
12:28
Morning guys I have a quick question I am using this funtion $.fn.serializeObject but my form has both strings and arrays. The strings are working fine but the arrays are not binding
$.fn.serializeObject = function () {
    var o = {};
    var a = this.serializeArray();
    $.each(a, function () {
        if (o[this.name] !== undefined) {
            if (!o[this.name].toString().indexOf(this.value) >= 0) {
                var str = o[this.name].toString();
                str += ", " + this.value;
                o[this.name] = str;
            }
            //o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
@Jefferson Please don't post unformatted code - use the up arrow to edit your post, then hit Ctrl + K to format the code in that post. See the faq. You have 25 seconds to edit and format your message properly before it will be removed. Please separate code blocks from your actual question. Put your question in 1 message and then your code in a 2nd and format it.
For posting large code blocks, use a paste site like like gist.github.com, hastebin.com, pastie.org or a demo site like jsbin.com
So for a textbox its working fine but for a multiselect dropdown its not working
13:03
var p = {
then: function(cb) {
cb( 42 );
}
};
// this works OK, but only by good fortune
p
.then(
function fulfilled(val){
console.log( val ); // 42
},
function rejected(err){
// never gets here
}
);
As we can see, p here is a thenable object(since it has a then property defined) not a genuine Promise.
Promise.resolve(..) will accept any thenable, and will unwrap it to its non-thenable value.
In below snippet: If 'p' is used to in resolve().. how could it log 42?
Promise.resolve( p )
.then(
function fulfilled(val){
console.log( val ); // 42
},
function rejected(err){
// never gets here
}
);
Does Unwrap call p.then() and logs 42? But how is that 42 passed as value to the last .then() so it could again log 42
14:03
wdym? You defined the property then to conform with the "thenable" interface. It states: "when I am called, call whatever function is passed to me with a single argument 42". You then call Promise.resolve on the thenable which creates a promise fulfilled with the value 42 as defined. Then you started a normal promise chain that got 42 as the orginal promise's value.
@Sadiq Essentially Promise.resolve(thenable) = thenable in terms of chaining more then()s to it.
Promises auto-flatten. Promises will also auto-flatten any thenable. Well, unless you try to do some wild stuff in the custom then but I'd not really count that as a realistic example.
@VLAZ since there is, apparently, a lot of confusion on the part of the OP, I'd go with "Promise.resolve(thenable) is a promise fulfilled to the value of the orginal thenable which is passed as the argument to the then callback", might be easier to grasp
I guess. All I'm trying to say is that the auto-flattening takes care of all of this. There is no way to have a thenable passed into the callback to a .then() You always get a plain value.
Sure, I just think the OP has a misconception of "Promise.resolve(..) will accept any thenable, and will unwrap it to its non-thenable value" as Promise.resolve doesn't do that but creates a new promise with the result of resolving the argument (which in case of a thenable object is whatever's passed to the callback of its then method)
I guess it can be called unwrapping, and I don't have any issues with the explanation, obviously, just suspect going back to basics of promises might be in order here.
14:30
i mean
unless the thenable is within a value that can be passed
;)
Which is when the "flattening" comes into play, yes
@OlegValteriswithUkraine Yes, but in the example I'm expecting p.then() to return value (instead of console.log) to trigger fulfilled
But in the example i can see that fulfilled is triggered with the value though value is not returned
The value is passed into the callback. The callback is:
function fulfilled(val){
console.log( val ); // 42
}
And essentially it's being called as fulfilled(42)
14:41
@OlegValteriswithUkraine I mean, triggering is alright and understandable but how fulfilled logs the value 42 since it is not returned from p.then()
what is returned isn't relevant if you aren't acting on the return.
@VLAZ How does fulfilled gets the value 42
if you tried to chain one more .then after that (on p), it'd throw an error
@Sadiq Closely reread the above, please. It's not doing what you think it's doing
@Sadiq cb( 42 )
14:46
Explaining again, calling Promise.resolve(x) creates a new promise with the result of resolving x, be it a thenable, a proper promise, or a plain value. The peculiarities of flattening something like { then: (cb) => cb({ then: (c) => c(42) }) aside for now, all the then that follow resolve(x) are methods of the proper promises. And as @KevinB rightfully mentioned, if you'd try to just use the then method of p more than once, it'd result in an error 'cause at that point [1/2]
[2/2] you'd just be calling a method normally, which, as defined, returns undefined.
it may help to not have repeated function names
as i can't just say "fulfilled" and it mean the function i want it to mean, since you used it in two places
@KevinB ye duplicate fulfilled callback names made the confusion i guess to understand things
the first one is mostly irrelevant
as it has zero effect on any other part of the code
ok let me try to get it once again
var p = {
    then: function fakeThenable(cb) {
        console.log(cb.name);
        cb( 42 );
    }
};
// this works OK, but only by good fortune
p.then(
    function (val){
        console.log( val ); // 42
    }
);
// As we can see, p here is a thenable object(since it has a then property defined) not a genuine Promise.
// Promise.resolve(..) will accept any thenable, and will unwrap it to its non-thenable value.
// In below snippet: If 'p' is used to in resolve().. how could it log 42?
Promise.resolve( p ).then(
if you run that code, you'll see that fakeThenable is ran twice, both times with a callback function that has no name
of course, if you named the function in the p.then, it'd have a name
14:57
@KevinB Yes, like u named it 'fakeThenable'
Ok let me take it step by step ..
@KevinB Promise.resolve( p ) .. returns the promise and after that, calls fakeThenable(undefined) .. right?
am I right till here
@OlegValteriswithUkraine where am I wrong? What happens otherwise
it resolves p according to normal semantics (which is where then of the thenable comes in) and then creates a new promise with state set to fulfilled and result set to what you've passed to the callback of the then method (I am trying to avoid saying that it "calls" the then method of the thenable as it's a more complex than that)
15:13
@OlegValteriswithUkraine Considering p.then = fakeThenable .. which has an argument cb .. So when Promise.resolve( p ) gets called how would any callback be passed to cb argument in then()? So I'm assuming it will be undefined..
i was expecting that as well, but then, it'd be problematic if it worked that way.
the promise doesn't need what the thenable returns... it needs what the then calls the cb with
as that's what it is currently resolved for
@Sadiq because that's the job of the engine, did you expect otherwise?
@KevinB ok.. but what would be passed to cb argument in fakeThenable?
it becomes more apparent if you construct a promise directly with the constructor and its executor. resolve and reject (or whatever you name them) are passed during runtime under the hood when the operation is performed, calling the executor.
@Sadiq ƒ () { [native code] }
15:22
@KevinB and f() is a native Function object right!
that's just a notation for function
ƒ wellthen (val){
    console.log( val ); // 42
}
@KevinB yes but you are refering to that
it's none of the functions you defined, it's one that is native
@KevinB yes its in ES and therefore native
what that means is that it's not, @Sadiq. It's just representation. A proper function object would have, for example, a prototype (function constructor).
it technically conforms, but it's just what allows you to use in end user code
15:27
@OlegValteriswithUkraine Yes i know its a representation but actually it is refers to the native Function object in Engine .. right?
i mean
does it matter?
you can't do anything with it outside of call it with an argument so that the engine can do what it does with it to determine what the thenable resolves to
sorry but I'm curious .. if my understanding is correct or not
@Sadiq which, specifically, do you refer to? NativeFunction, function object, or that whether it's an instance of Function constructor?
function object .. not instance of Function constructor
technically, yes, it's a "member of the Object type that may be invoked as a subroutine". It even is an instance of Function
to be more precise, those functions are, indeed, "function object" as defined per: tc39.es/ecma262/multipage/…
if that's what you meant by "native Function object" - then yup, you got it right
{
    new Promise((r,j) => {
        console.log(r instanceof Object) // true
        console.log(r instanceof Function) // true
        console.log(Object.getPrototypeOf(r)) // f() { [native code] }
    })
}
15:45
ok
var p = {
    then: function fakeThenable(cb) {
        console.log(cb.name);
        cb( 42 + 2);
    }
};
So now ,
Promise.resolve( p )
.then(
function fulfilled(val){
console.log( val ); // 44
}
}
will log 44 ..
i'm not sure why you'd expect it not to
42+2 is no different than that just being 44
hmm..
i understand
15:59
@Sadiq which is expected as when you use operators, first, the result is obtained and then the result is used as the value. Post/pre increment shenanigans aside, that is
actually what confusing me was the cb in fakeTheable(cb), that will be passed to it .. so i think it is the one in red (bold, prototype linked with Function) created at runtime
yes, the callback is literally created and passed when the engine performs the operation as described
Thanks for bearing with me with patience.. you guys helped me a lot
NP - understanding promises can get confusing
I normally suggest carefully reading the spec first, but the way the operations are described is not straightforward by any means.
16:36
Why did I randomly get +1 reputation and my stats aren't showing why?
16:46
An answer you downvoted got deleted
@JoshuaWootonn Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
 
1 hour later…
18:02
@KevinB oh, thanks. Happens every once a while and just wanted to know why
i get between 2 and 7 a day
 
1 hour later…
19:33
posted on October 03, 2023 by Prudhvikumar Bommana

 The Stable channel has been updated to 117.0.5938.149 for Mac and Linux and 117.0.5938.149/.150 for Windows, which will roll out over the coming days/weeks. A full list of changes in this build is available in the log.  Security Fixes and Rewards Note: Access to bug details and links may be kept restricted until a majority of users are updated with a fix. We will also retain r

 
2 hours later…
21:16
I know that, Promise.resolve(p); returns the same promise, considering that 'p' is a genuine promise. But in following example, at resolve( p3 ); -- p3 will unwrap right there in p1. That means, Promise.resolve(p); And resolve(p3), inside a constructor behaves differently. As the first approach returns the promise as is while the latter resolves it inside the constructor .. Am I right?
var p3 = new Promise( function(resolve,reject){
resolve( "B" );
} );
var p1 = new Promise( function(resolve,reject){
resolve( p3 );
} );
var p2 = new Promise( function(resolve,reject){
resolve( "A" );
} );
p1.then( function(v){
console.log( v );
} );
p2.then( function(v){
console.log( v );
} );
21:29
Or may be I'm wrong
resolve( p3 ); will resolve to p3. But since .then() is not called on it.. So, to which handler would it register to?
p1.then( function(v){
console.log( v ); // i know this will log 'B', but when did it register to this handler?
} );
p1 can't resolve p3 until after p3 is resolved
though, i suppose you're wondering why A finishes first. it's because the callback to p1.then doesn't get added to the queue until after the next tick, due to resolve( p3 ) being resolving to the result of another promise, pushing it off for one more tick than p2
you can get the same result if you omit p3 and just directly resolve( Promise.resolve( 'b' ) )
21:44
@KevinB Oh got it!
in practice this order doesn't often matter
because promises are mostly used for things outside of the realm of javascript, such as http requests or database queries
@KevinB yes no confusion in tht part
@KevinB hmm.. depends on situation
21:57
@KevinB As p1 resolves to p3. Then p3 resolves to value "B", while p3 has no handler attached. So the value is implicitly returned to the waiting p1, which has the handler attached and thus logs the value "B". Right?
 
2 hours later…
23:47
You can register a then callback on p3, and the resolver function will still get the value because it gets the promise. Registering then or catch callbacks only affects propagation through their chain.

« first day (4735 days earlier)      last day (437 days later) »