FAQ Database Discussion Community


State pattern: Identify state class type from string

java,design-patterns,state
Background I have a command that uses the state pattern. When the command state changes I am notified in the UI that for example class stageOneState is now the active state. Is it bad practice to check the state class type using a string as an identifier? Is this undoing...

Android - Save in app browser state (page + place in page) when app is interrupted

android,browser,state,interruption
Part of my app is opening the browser in app and sending the user to a dedicated webpage (lets call it "FirstPage"). There the user can navigate throw the web pages. That works great, but when the user is in the webpages and the app gets interrupted (by incoming call...

State Machine in Python: Run Code in Transition or State?

python,state,transitions
I am rather new to the python language, please bear with me on this one. I want to run two state machines in two separate threads, communicating to each other via a queue. I used the transitions package to create the state machine. My understanding is that all actions/code that...

Passing query string from #new to #create

ruby-on-rails,rest,controller,state
I am trying to update my inventory after a Stripe transaction routes: get 'product/:size' => 'charges#new' resources :charges ex: localhost:3000/product/32 controller def new @product = Product.find_by(size: params[:size]) end def create @amount = 500 @product = Product.find_by(size: params[:size]) customer = Stripe::Customer.create( :email => '[email protected]', :card => params[:stripeToken] ) charge = Stripe::Charge.create(...

Call State Always : “ERROR_USER_UNAVAILABLE” Linphone manager Android

android,state,phonecalls,linphone
I want to make application that can call with using Linphone library, but why when I want to call a number (this number can be called using usual phone apps), it always state : "ERROR_USER_UNAVAILABLE" private void call(String ticket_id) { updateState("CALLING"); Log.d(TAG_CALL, "try to call"); LinphoneManager.getInstance().newOutgoingCall(msisdn, ticket_id); callingAttemptHandler.postDelayed(callingAttempt, 1000 *...

Angular ui.router. Deep nested routes

angularjs,nested,angular-ui-router,state
Here is an example to check http://embed.plnkr.co/uVMlkk/preview When we navigate to 'page2' route there is a 'hey, I'm a subroute' note. But once we navigate anywhere else that note will disappear forever. The goal is to make some nested states to be shown right away (as a default ones). I...

Detecting multiple key presses in C# and XNA 4.0

c#,keyboard,xna,state
I want to detect if a specific set of keyboard keys are being held down at once in C# and XNA 4.0. I'm doing so with the following code: KeyboardState keyState = Keyboard.GetState(); if(keyState.IsKeyDown(Keys.S) && keyState.IsKeyDown(Keys.K) && keyState.IsKeyDown(Keys.I)) { //Do something } This code detects if the user is pressing...

Multiple “when”-conditions for a State

qml,state,qt-quick
Say I have following states: State { name: "red_state" when: color === "red" }, State { name: "blue_state" when: color === "blue" }, State { name: "square_state" when: shape === "square" }, State { name: "circle_state" when: shape === "circle" }, State { name: "blue_circle_state" when: color === "blue" &&...

Angular routing and state handling problems

angularjs,nested,angular-ui-router,state
I have 3 nested states: $stateProvider .state('A', { url: '/a', templateProvider: function ($templateCache) { return $templateCache.get('pages/a.html'); }, controller: 'aController' }) .state('A.B', { url: '/b', templateProvider: function ($templateCache) { return $templateCache.get('pages/b.html'); } controller: 'bController' }) .state('A.B.C', { url: '/c', templateProvider: function ($templateCache) { return $templateCache.get('pages/c.html'); }, controller: 'cController' }) Let's say...

Handsontable - Metadata definition object

merge,save,metadata,state,handsontable
In Handsontable, it is possible to get data object via getData function. I also need to save metadata of Handsontable instance e.g. actual column sizes, merged cells etc. Is it possible to get one object which describes actual state of table and use it to save and load state along...

Hidden params when using $state not working - AngularJS, Ionic

angularjs,url,state,params,ionic
I'm a beginner using the ionic framework. I'm trying to use stateParams with a state but I don't want it to be exposed in the URL. I could use stateParams when it's added to the URL (url/:param1) but when I tried to declare it under 'params' as mentioned here [...

Using N-Tier Entity Framework, how can I access an entity that has been marked as deleted?

c#,entity-framework,state,n-tier
Note: My project is using N-Tier Entity Framework (https://ntieref.codeplex.com/), which is different than regular Entity Framework. On the Client side, when I attempt to access an entity that has been marked as deleted, it does not show up in my foreach loop. foreach (var entity in DataContext.EntitySet.Where(x => x.ChangeTracker.State ==...

AngularJS ui-router abstract state with second child

angularjs,angular-ui-router,state,abstract
I have a problem to load second child of state. Url is changed, but page not loading. .state('app', { abstract: true, template: '<ui-view/>', controller: 'myControl', data: { requireLogin: true } }) .state('app.CarsList', { params: { id: ':id' }, url: '/Companies/:name', templateUrl: 'CarsList.html', }) .state('app.CarsList.CarInfo', {// second child url: '/Info', templateUrl:...

How to preserve loaded javascript content in a WebView when loading a new page?

javascript,cocoa,webview,state
In a WebView I can load javascript code by running view.stringByEvaluatingJavaScriptFromString or loading the code directly in the JS context you can retrieve via view.mainFrame.javaScriptContext. However, when I navigate to a new URL (be it in the WebView.mainFrame or in Javascript, e.g. by setting window.location) all my javascript code is...

How to pass data between views using stateParameters (not routes) in AngularJS

angularjs,controller,state
I have some views in my applications, and I have hard time to show the data when moving from one view to another. I have a list of news and when I click on the particular news I want the view for that particular news to be shown. Here is...

Haskell State monad with tuples as state

haskell,state,monads
My apologies if my question is stupid (I'm still quite new to monads), but I couldn't find the answer to it so far. I want to store pairs as the state in the State monad. However, if I try this on a simple example of (Int, Int) I get (ghci):...

React - Updating state for each child component

javascript,events,components,state,reactjs
Not sure if i'm understanding this correctly. If i'm making a child component, type button, that increments its own counter, is it possible to do so without having 2 separate functions? the following i've done seems like a hack? what if theres X amount of buttons, how would i refactor...

Capture UI router's state change when there is no change

angularjs,angular-ui-router,state
I would like to use UI router's $stateChangeStart to capture state change when transiting from '/foo/bar' to '/foo/bar': $rootScope.$on('$stateChangeStart', function() { // ... });' Essentially, I would like to capture when the link for the current state was clicked so I can force reload....

Inject a template in parent's view with ui-router

angularjs,nested,angular-ui-router,state
I have an abstract state declared as $stateProvider.state('myapp', { abstract: true, templateUrl : 'index.html' }); And all the <ui-view> in the 'index.html' template will be populated by the children states: $stateProvider.state('myapp.home', { url : "/", views : { "main" : { controller : 'HomeCtrl', templateUrl : 'includes/home.html' } } });...

Get the key of an unknown entity [duplicate]

c#,entity-framework,primary-key,state,dbcontext
This question already has an answer here: Get the primary key value of an arbitrary entity in code first 1 answer Hello I would like to get the primary key value. public static void Look(LEBAEntities db, object obj) { // if getPrimaryKey(obj) == 0 db.Entry(obj).State = EntityState.Added; // else...

angular: state change looses URL at second click

angularjs,angular-ui-router,state
I have 4 states, each representing a different visualization. The first visualization is a map, the second to fourth are pie charts. The default is the map visualization. I have three icons showing always the other 3 possible visualizations. Each of the state is actually a nested state. The first...

Complicated state transitions: best practices

c,state,state-machines,state-machine-workflow
I work with embedded stuff, and I have some software module that manages hardware. This module has state, and state transitions are complicated: depending on events, the module could go from state A to state B or probably to C. But, when it exits some state, it should perform some...

LinkedIn Rest API, State token doesn't match

android,android-webview,token,linkedin,state
I am referring this to authorize, authenticate and login to LinkedIn account using Rest API, but now i am facing problem, the WebView where i am displaying the LinkedIn Rest API call url view, is returning blank with message as "State token doesn't match" It was working fine earlier, but...

C# and Oracle, login Form: Operation is not valid due to the current state of the object

c#,oracle,object,state
private void bLogIn(object sender, EventArgs e) { string logging = "select * from CLIENT where LOGIN='" + this.t_Login.Text + "' and PASSWORD='" + this.t_Password.Text + "' ;"; OracleConnection conn = new OracleConnection("Data Source=XXX/orcl;User Id=XXX;Password=XXX;"); OracleCommand cmd = new OracleCommand(); cmd.CommandText = logging; cmd.Connection = conn; try { conn.Open(); }...

ReactJS modify parent state from child component

state,reactjs
I'm trying to remove an item from my state array when clicked. At the moment I have an onclick listener which calls a function passed into the props. However I get a warning: bind(): React component methods may only be bound to the component instance. See App... and it does...

Common pattern of scan() where I don't ultimately care about the state

scala,state,fold
I find myself constantly doing things like the following: val adjustedActions = actions.scanLeft((1.0, null: CorpAction)){ case ((runningSplitAdj, _), action) => action match { case Dividend(date, amount) => (runningSplitAdj, Dividend(date, amount * runningSplitAdj)) case s @ Split(date, sharesForOne) => ((runningSplitAdj * sharesForOne), s) } } .drop(1).map(_._2) Where I need to accumulate...

State of a bound parameter in a promise

javascript,state,lifecycle,page-lifecycle
I'm curious about the timing when I bind something to a promise. var that = this; function p(){ var promise = new Promise( function (yes, no) { /* .... */ /* .... */ }).then(function (val) { /* .... */ /* .... */ }.bind(this)); }.bind(this) Will the condition that === this...

How to preserve the state of toggle button in listview in android

android,listview,state,togglebutton
i have listview with toggle button.i face a problem when i scroll down the toggle button the state of toggle button changed,and also when i click on first toggleButton the fourth toggle button also checked. i also want to save the all toggle button states and the text on that...

AngularJS UI Router - $state.current.name is empty when using templateUrl

angularjs,angular-ui-router,state
I am using ui router for Angular and trying to get the name of the current state. After 3 days working on it, I found out that it is empty when I use templateUrl. After changing it to template: 'test', state name magically appears... Is it possible to make it...

Configuring UI Router states based on configuration

angularjs,state,angular-ui-router
Is there a way to configure a UI Router states based on Server Side JSON file. I wan't to avoid hard coding the States inside my module.config(..). I firstly thought of having controller which has the state map data available which can just call $stateProvider. However, I believe, controllers cannot...

AngularJS Transition to sibling of abstract state from sibling

angularjs,nested,angular-ui-router,state,siblings
I have been working with angular-ui-router and trying to transition to a child of one of my abstract states from within another child of the same abstract. this diagram shows the Idea a bit better: So where 'R' is say the module and 'blue 1' is my abstract state with...

Scala - State in closure / anonymous function

scala,closures,state
I'm trying to take elements from a list while a specific predicate is satisfied. The predicate however depends on the last element. This is some code illustrating the problem and my solution val list = List(1,2,3,1,4) list.takeWhile { // state inside the closure?! var curr = 0 // actual function...

How to conditionally check the state of an openstack instance

cloud,state,conditional-statements,ansible,openstack
I am trying to conditionally check the state of an openstack cloud instance in my playbook. The playbook itself takes the name of a cloud instance as a parameter and then deletes it by setting the state to absent using nova compute. What I want to do is check if...

Android preserving state inconsistencies

android,state,android-lifecycle
as a new android developer I'm trying to adopt the android mindset. I faced a problem while preserving the state of an activity, because onSavedInstanceState does not seem to work consistently between different versions of Android. Prior to version 3, onSavedInstanceState would preserve data even when the app got killed...

AngularJS $location.path looping back to root

javascript,html,angularjs,angular-ui-router,state
I've looked everywhere, but none of the potential solutions have worked. The sign-in page is supposed to route to the tabs page upon a successful login or registration. For some reason it is directing back to the root, or otherwise state every time. Does anyone have any suggestions? Thanks! States:...

How to delete functions of previous instances of controller?

javascript,angularjs,controller,state,reload
I have a simple angularjs controller referenced as someCtrl and it contains the following code: function testing() { console.log("Hello there."); } $document.on('click', function(e) { testing(); }); this.getView = function(value) { return viewService.getView(value); }; this.setView = function(value) { viewService.setView (value); }; this.destroy = function() { $state.reload('default_state'); }; When click event happens,...

UI-Router $stateParams With Master Detail Pattern

javascript,angularjs,nested,angular-ui-router,state
I need a Master Detais pattern for my web site. In index lots of thumbnails and every thumbnail link to their detailed page. I make a progress but does not get to work. Its load thumbnails on index oage but when I click to thumbnails its load blank page. Index:...

Ui Router: composite view render view once

javascript,angular-ui-router,state,composite-view
What I want to achieve is have 2 sibling views, where 1 is run-once and the other will get updated. I have a template like so: <body> <ui-view="header /> <ui-view="body" /> </body> And I have 1 catch-all state: .state('root', { params: { … }, resolve: { data: fn() { …...

How do i keep UISwitch state when changing ViewControllers?

ios,swift,state,uiswitch
When I move from one view controller to another, the switch on the first controller resets itself and does not retain its state. How can I make it save its state when come back to it after viewing other controllers? And how do I make it save its state after...

React Native Change State With Unexpected Logging

javascript,state,react-native
For context, I am working on this React Native Tutorial The way this logs confuses me. The following is the console output when I changed an empty input field by typing "a" then "b". Here's my SearchPage class. Why does console.log('searchString = ' + this.state.searchString); show the previous value for...

Telescope back button state

javascript,meteor,state,telescope
Checking Telescope, and it looks pretty great, but... Is the back button broken when using search? After entering a search term, if you click on a thread and then hit the browser's back button, Telescope displays the correct search url, but there are no search results. This makes using search...

Angular ui router passing data between states without URL

angularjs,angular-ui-router,state,params
I am facing this problem of passing data between two states without exposing the data in the url, it's like user cannot really directly land on this state. For example. I have two states "A" and "B". I am doing some server call in state "A" and passing the response...

I require assistance for converting pseudo code to Java (State machine examples)

java,state
Hello i am writing this because i have tried to convert the pseudo code below into java formatting fir around 2 days. The code i was trying to convert came from this amazing article: http://gamedevelopment.tutsplus.com/articles/how-to-build-a-jrpg-a-primer-for-game-developers--gamedev-6676 The code is class StateMachine Map<String, IState> mStates = new Map<String, IState>(); IState mCurrentState =...

Code Parallel.For works only in Debug mode

c#,tuples,state,parallel.foreach,parallel.for
This code works correctly only in Debug mode. I can't understand what is wrong. I've tried to modify the code, but without any progress. I would like add the result of calling the function newRow to hashSet if the first parameter is true. foreach (structNumbers sn in numbers) //Parallel.ForEach(numbers, new...

UI-Router : Prevent access to parent state

angularjs,angular-ui-router,state
I am moving to UI-Router as my App router. I want to have nested state as below: $stateProvider .state('app', { url: '/app', template: ' <div ui-view></div>', authenticate: true }) .state('app.state1', { url: '/state1', templateUrl: 'app/state1.html', controller: 'State1Ctrl', controllerAs: 'state1', authenticate: true }) .state('app.state2', { url: '/state2', templateUrl: 'app/state2.html', controller: 'State2Ctrl',...