Pretty new to Javascript. Hopefully this is a quick question (otherwise I can make a post about it): The following does what I expect: let o = { b: 'B'};let wrap = (i) => (() => { return [i];});o["b"] = wrap(o["b"]);console.log(o["b"]()). But I don't understand why the following has different behavior: let o = { b: 'B'};o["b"] = (() => {return [ o["b"] ];});console.log(o["b"]())
@MarkS. 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.
Please don't post unformatted code - hit Ctrl+K before sending, use up-arrow to edit messages, and 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.
The sandbox link to in the room rules doesn't work, and I can't get the Ctrl+K to work properly somehow. I'll try again some other time. Thanks though!
@miqh 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.
I'm in a situation where the server is returning a huge pile of JSON, which I'm mapping to various objects, then trickling down to different layers of components. My problem is that some of the component layers offer editing capability (i.e. tracking draft values).
I'm trying to decide whether it's better to keep track of all possible draft values at the top-most component that acts as the client-server boundary, versus using another approach like the key prop to simply destroy and recreate all the component layers underneath.
(Obviously not using any state management frameworks like Redux.)
Why didn't anybody tell me about npx? It seems REALLY USEFUL and I didn't know about its existence. It can run a module you have locally installed in your project, so instead of adding "gulp": "gulp" to the scripts section in package.json then using npm run-script gulp MyTask you can just do npx gulp MyTask.
I have a question for unit tests. I'm setting up Chai+Mocha (not sure if this really matters) however the current project doesn't use modules yet. I'd like to work on the modules later, but have unit tests first. Would that be a problem for unit testing some functionality? Can I import the file and work with the global thing it defines?
Also, I'm open to using non-Chai+Mocha setup if anybody has better recommendation.
Also, Visual Studio is annoying the hell out of me. It randomly decides to indent something with spaces when it's set to use tabs. Then it underlines the indenting whitespace because it's inconsistent.
But because it now contains some spaces, pressing Tab adds spaces because...why not?
Deleting the entire whiespace at the beginning of the line doesn't help, either. VS just set the intentation to "mixed", so it just assumes that any further indentation is going to be spaces only.
@JBis wrap(o["b"]) says take the value of o["b"] and pass it into the wrap function. But since I haven't called a function in o["a"] = (() => { return [o["a"]];});, the behavior is different?
Yeah...then the whole linting goes out. I found people are easier to accept good practices if you don't beat them over the head with a stick. Metaphorically speaking. They also don't like it when done literally.
My aim is to say "Change these settings in your IDE" and then it would handle everything.
Technically undefined isn't the same as null language-wise but anything else I've used will both colour them to match as you want the value to stand out.
@MarkS. Yes. In the first example, you are getting the value, and passing that to the wrap function. Once the "get the value" occurs, it will use that value for ever. The difference in the second one, is that you are getting the value live, you are getting the value when the function is called not before.
@BartekBanachewicz Please don't post unformatted code - hit Ctrl+K before sending, use up-arrow to edit messages, and 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.
it's not quite what I want, because again I want a copy for change revert, but immediate preview
and viewmodel makes a copy but only moves to model once you submit
but i can fix that by temporarily removing the original object from the collection and rendering the selected one separately
so that's okay
what's not okay is that my Time seems to completely break with the viewmodel - it actually propagates through to the model immediately and doesn't register as a change
i suspect the issue is that i'm using my own function addMinutes
class Todo {
@observable title = "Test"
}
const model = new Todo()
const viewModel = createViewModel(model);
autorun(() => console.log(viewModel.model.title, ",", viewModel.title))
// prints "Test, Test"
model.title = "Get coffee"
// prints "Get coffee, Get coffee", viewModel just proxies to model
viewModel.title = "Get tea"
// prints "Get coffee, Get tea", viewModel's title is now dirty, and the local value will be printed
class Todo {
@observable title = "Test"
}
const model = new Todo()
const viewModel = createViewModel(model);
it doesn't wrap model or createViewModel in an observable
@BartekBanachewicz wdym? just modify the instance directly
If i'm not making any sense, I know someone who's really good at Mobx (he used to be a moderator here but left). I can give you his discord if you want.
i'm kinda suspecting that it might not be quite up to the challenge
i might just go to my manual change tracking, but implement it better
but it's kinda weird that like, noone else hits this problem?
> You may use observable arrays, maps and objects with createViewModel but keep in mind to assign fresh instances of those to the viewmodel's properties, otherwise you would end up modifying the properties of the original model.
Does this construct make sense? It's like a conditional identity function but it might optionally transform the input. Essentially, the idea is that at the end you'll normalise to the same type.
It's related to this thing you looked at more than a week ago. It's the .of() method.
On very slightly related note - any good URL shorteners? I've been using bit.ly mostly because it shows up first in the search results. Tried shorturl.to but it seems my link from it is gone. I guess they don't retain if for long
@JoeSaad I'd prefer your current solution, honestly, as it makes it vastly easier to read and maintain. The fact that it's two lines instead of one is negligible - you'd be reading it a lot more times than you'd be writing it. Here is the syntax to do it with destructuring if you want but it really doesn't make it that much shorter, either.
I'm trying to publish my ionic2 app on Google play.But still, I cannot do that.It doesn't show any errors.Can you tell me how to do this?
When I press the "Ready to Publish" button then it shows below screen.
@AaronJohn Sabu 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.
I'd definitely start with analysing whether you actually need the function to run in the background. Generator functions and setInterval might be a good solution, too.
The other way is calling something external and waiting for a response. In a browser that is probably going to be an AJAX call to a backend, while in a server you can call another process and wait to be notified upon completion. Neither is really "multi-threading", though. I'm not aware of any other easy choices - there might be more specialised ones.