state

React setState not Updating Immediately

狂风中的少年 提交于 2019-11-26 14:41:47
I'm working on a todo application. This is a very simplified version of the offending code. I have a checkbox: <p><input type="checkbox" name="area" checked={this.state.Pencil} onChange={this.checkPencil}/> Writing Item </p> Here's the function that calls the checkbox: checkPencil(){ this.setState({ pencil:!this.state.pencil, }); this.props.updateItem(this.state); } updateItem is a function that's mapped to dispatch to redux function mapDispatchToProps(dispatch){ return bindActionCreators({ updateItem}, dispatch); } My problem is that when I call the updateItem action and console.log the state

Using static variables instead of Application state in ASP.NET

有些话、适合烂在心里 提交于 2019-11-26 14:41:26
I plane to use static variables instead of Application state in ASP.NET and am wondering if this is correct approach: [Global.asax.cs] ... public class Global : System.Web.HttpApplication { void Application_Start(object sender, EventArgs e) { // Code that runs on application startup } ... private static Dictionary<string, object> cacheItems = new Dictionary<string, object>(); private static object locker = new object(); public static Dictionary<string, object> CacheItems { get { lock (locker) { return cacheItems; } } set { lock (locker) { cacheItems = value; } } } public static void

Replace individual list elements in Haskell?

风格不统一 提交于 2019-11-26 14:06:19
问题 I have a list of elements and I wish to update them: from this: ["Off","Off","Off","Off"] to this: ["Off","Off","On","Off"] As I am somewhat new to Haskell, I have been using (x:xs)!!y to extract and update individual components using the function: replace y z [] = [] replace y z (x:xs) | x==y = z:replace y z xs | otherwise = x:replace y z xs and then entering the following in ghci: (replace "Off" "On" ["Off",'Off","Off","Off"]) !! 2 I get the following: "On" I seem to be able to extract and

How can you do anything useful without mutable state?

扶醉桌前 提交于 2019-11-26 12:49:01
问题 I\'ve been reading a lot of stuff about functional programming lately, and I can understand most of it, but the one thing I just can\'t wrap my head around is stateless coding. It seems to me that simplifying programming by removing mutable state is like \"simplifying\" a car by removing the dashboard: the finished product may be simpler, but good luck making it interact with end-users. Just about every user application I can think of involves state as a core concept. If you write a document

React setState not updating state

冷暖自知 提交于 2019-11-26 12:22:47
So I have this: let total = newDealersDeckTotal.reduce(function(a, b) { return a + b; }, 0); console.log(total, 'tittal'); //outputs correct total setTimeout(() => { this.setState({dealersOverallTotal: total}); }, 10); console.log(this.state.dealersOverallTotal, 'dealersOverallTotal1'); //outputs incorrect total newDealersDeckTotal is just an array of numbers [1, 5, 9] e.g. however this.state.dealersOverallTotal does not give the correct total but total does? I even put in a timeout delay to see if this solved the problem. any obvious or should I post more code? setState() is usually

React - setState() on unmounted component

旧时模样 提交于 2019-11-26 12:10:04
问题 In my react component im trying to implement a simple spinner while an ajax request is in progress - im using state to store the loading status. For some reason this piece of code below in my React component throws this error Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the undefined component. If I get rid of the first setState call the error goes away. constructor(props) {

Why does stringstream >> change value of target on failure?

北城以北 提交于 2019-11-26 10:33:54
From Stroustrup's TC++PL, 3rd Edition, Section 21.3.3: If we try to read into a variable v and the operation fails, the value of v should be unchanged (it is unchanged if v is one of the types handled by istream or ostream member functions). The following example appears to contradict the above quote. Based on the above quote, I was expecting the value of v to remain unchanged -- but it gets zeroed. What's the explanation for this apparent contradictory behaviour? #include <iostream> #include <sstream> int main( ) { std::stringstream ss; ss << "The quick brown fox."; int v = 123; std::cout <<

android fragment onRestoreInstanceState

十年热恋 提交于 2019-11-26 10:28:44
问题 Am I missing something or do Fragment s not have a onRestoreInstanceState() method? If not, how do I go about attaining something similar? 回答1: Fragments do not have an onRestoreInstanceState method. You can achieve the same result in onActivityCreated , which receives a bundle with the saved instance state (or null). Check the source code here. 回答2: I know, that you have accepted answer, but you should read the official documentation about fragments, and it says (paragraph "Handling the

Preserving global state in a flask application

。_饼干妹妹 提交于 2019-11-26 10:26:03
问题 I am trying to save a cache dictionary in my flask application. As far as I understand it, the Application Context, in particular the flask.g object should be used for this. Setup: import flask as f app = f.Flask(__name__) Now if I do: with app.app_context(): f.g.foo = \"bar\" print f.g.foo It prints bar . Continuing with the following: with app.app_context(): print f.g.foo AttributeError: \'_AppCtxGlobals\' object has no attribute \'foo\' I don’t understand it and the docs are not helping at

Angularjs ui-router. How to redirect to login page

隐身守侯 提交于 2019-11-26 10:17:59
问题 I have 4 states: dashboard , dahboard.main , dashboard.minor , login . dashboard is abstract and it is a parent state for .minor and .main states. Below is my code: .state(\'dashboard\', { url: \"/dashboard\", abstract: true, templateUrl: \"views/dashboard.html\", resolve: { auth: function ($q, authenticationSvc) { var userInfo = authenticationSvc.getUserInfo(); if (userInfo) { return $q.when(userInfo); } else { return $q.reject({ authenticated: false }); } } }, controller: \"DashboardCtrl\",