case FD_READ: #ifndef NOSOCKETSTATES if (pSocket->GetState...pSocket->SetState(connected); if (pSocket->GetState...pSocket->SetState(connected); if (pSocket->GetState...= listening && pSocket->GetState() !...= connected && pSocket->GetState() !
(); } public String getState() { return state; } public void setState(String...(); } public String getState() { return state; } public void setState(String...; } else { this.state = this.memento.getState(); } } public String...getState() { return state; } public void setState(String state) { this.state...()); originator.restoreMemento(); System.out.println(originator.getState()); } }
start(); Thread.sleep(2000L); // 等待thread1执行结束,再看状态 System.out.println("等待两秒,再看thread1当前状态:" + thread1.getState...().toString()); thread2.start(); System.out.println("调用start方法,thread2当前状态:" + thread2.getState().toString...()); Thread.sleep(200L); // 等待200毫秒,再看状态 System.out.println("等待200毫秒,再看thread2当前状态:" + thread2.getState...Thread.sleep(3000L); // 再等待3秒,让thread2执行完毕,再看状态 System.out.println("等待3秒,再看thread2当前状态:" + thread2.getState...().toString()); thread3.start(); System.out.println("调用start方法,thread3当前状态:" + thread3.getState
pSocket->SetState(connected); 46 if (pSocket->GetState...check if there's data waiting 63#ifndef NOSOCKETSTATES 64 if (pSocket->GetState...= listening && 139 pSocket->GetState() !...= connected && 148 pSocket->GetState() !...() == listening || pSocket->GetState() == attached) && (pSocket->m_lEvent & FD_ACCEPT)) 343#endif /
(reducer, initialState) { let currentState = initialState, listeners = []; function getState...());//begin undefined store.subscribe(() => console.log('触发了action',store.getState())); store.dispatch...({type:'ADD'});//触发了action {sum: 1} console.log('end',store.getState());//end {sum: 1} 这样的话是有问题的,就是我们不去...()); store.subscribe(() => console.log('触发了action',store.getState())); store.dispatch({type:'ADD'});...console.log('end',store.getState()); 至此我们的简易版redux的createStore就实现了。
thread1 执行了"); } }); System.out.println("没调用start方法,thread1当前状态:" + thread1.getState...Thread.sleep(2000L); // 等待thread1执行结束,再看状态 System.out.println("等待两秒,再看thread1当前状态:" + thread1.getState...toString()); thread2.start(); System.out.println("调用start方法,thread2当前状态:" + thread2.getState...()); thread3.start(); System.out.println("调用start方法,thread3当前状态:" + thread3.getState...; // 再等待3秒,让thread3执行完毕,再看状态 System.out.println("等待3秒,让thread3抢到锁,再看thread3当前状态:" + thread2.getState
Runnable() { @Override public void run() { System.out.println("thread1当前状态:" + Thread.currentThread().getState...)); System.out.println("thread1 执行了"); } }); System.out.println("没调用start方法,thread1当前状态:" + thread1.getState...); Thread.sleep(2000L); // 等待thread1执行结束,再看状态 System.out.println("等待两秒,再看thread1当前状态:" + thread1.getState...().toString()); thread2.start(); System.out.println("调用start方法,thread2当前状态:" + thread2.getState().toString...()); Thread.sleep(200L); // 等待200毫秒,再看状态 System.out.println("等待200毫秒,再看thread2当前状态:" + thread2.getState
所以我们就有了createStore这个函数帮我们生成store, 然后将getState 跟 dispatch 方法export出去。...function createStore(state, stateChanger) { const getState = () => state; const dispatch = (action...) => stateChanger(state, action) return {getState, dispatch} } createStore 接受两个参数,一个是表示app的 state。..., dispatch, subscribe} } 我们就可以这样使用 store.subscribe(() => renderApp(store.getState())) 由此可以看出,dispatch...())) // 首次渲染页面 renderApp(store.getState()) // 后面可以随意 dispatch 了,页面自动更新 store.dispatch(...)
So easy,直接前后都加上console.log(store.getState())就可以了不是吗?...但是有以下几点需要注意下: 自定义中间件可以获取到createStore的dispatch(action)和getState()方法。...我们现在写的中间件是无法从函数内部中获取到dispatch(action)和getState(),所以我们需要多写一层函数,传入dispatch(action)和getState()。...为了简洁,我们可以传入一个对象,包含了入dispatch(action)和getState()两个方法 function dispatchAndLog2({dispatch,getState}){...let _dispatch=store.dispatch let _getState=store.getState let chain = middlewares.map(function
return action } // 初次调用的时候 首先执行一次 dispatch dispatch({type: '@@redux/firstTime'}) return {getState...注意 Store的方法 getState() 返回应用当前的state树 dispatch(action) 分发action 这是触发state变化的唯一途径 subscribe...你可以在回调函数里调用 getState() 来拿到当前 state。...function addIfOdd() { return (dispatch, getState) => { const currentValue = getState();...const middlewareAPI = { getState: store.getState, dispatch: (action) => dispatch(action)
() { if (isDispatching) { throw new Error( 'You may not call store.getState() while the..., ... }}复制代码通过源码我们可以基本清楚,通过执行createStore方法,最终会返回一个store对象,该对象主要暴露几个属性,我们主要关注比较常用的:dispatch、getState...、getState,看下实际用例:import createStore from 'redux'// 创建一个reducerfunction reducer(state={}, action) {...方法和dispatch方法 const middlewareAPI = { getState: store.getState, dispatch: (...args) => dispatch...: store.getState, dispatch } }}复制代码logger中间件 function logger({getState, dispatch
() { if (isDispatching) { throw new Error( 'You may not call store.getState() while..., ... } } 通过源码我们可以基本清楚,通过执行createStore方法,最终会返回一个store对象,该对象主要暴露几个属性,我们主要关注比较常用的:dispatch、getState...、getState,看下实际用例: import createStore from 'redux' // 创建一个reducer function reducer(state={}, action)...方法和dispatch方法 const middlewareAPI = { getState: store.getState, dispatch: (...args) =...: store.getState, dispatch } } } logger中间件 function logger({getState, dispatch
state初始值', () => { const store = createStore(testReducer, {sum: 520}); expect(store.getState...测试dispatch', () => { const store = createStore(testReducer, {sum: 0}); expect(store.getState...()).toEqual({sum: 0}); //加一 store.dispatch({type: 'ADD'}); expect(store.getState...()).toEqual({sum: 1}); //减一 store.dispatch({type: 'DEC'}); expect(store.getState...如果错误是会报错的,例如把初值的期待值写为-1 expect(store.getState()).toEqual({sum: -1}); 这样就会报错了,显示出来 ?
return state } } let store = createStore(counterReducer) store.subscribe(() => console.log(store.getState...3: getState:获取当前的状态。 4: replaceReducer:替换reducer。...上面是redux-logger中间件的简单实现,常用的中间件还有redux-thunk,核心代码如下: const thunk = ({ dispatch, getState }) => next =>...action => { if (typeof action === 'function') { return action(dispatch, getState) } return...next(action) } redux-thunk的逻辑也很简单,通过对store解构获取dispatch和getState函数,如果action是函数则调用action,否则调用next(action
function createStore(state, stateChanger) { const getState = () => state; const dispatch = (action...) => stateChanger(state, action) return {getState, dispatch} } createStore 接受两个参数,一个是表示app的 state。..., dispatch, subscribe} } 我们就可以这样使用 store.subscribe(() => renderApp(store.getState())) 这样,我们的renderApp..., dispatch, subscribe } } 总结以下:store对象里的方法主要做三件事 getState : 获取组件状态 dispatch :改变组件状态 subscribe : 订阅组件变化...())) // 首次渲染页面 renderApp(store.getState()) // 后面可以随意 dispatch 了,页面自动更新 store.dispatch(...)
@Override public void run() { // ... } }); // 获取线程状态 Thread.State state = thread.getState...Thread currThread = Thread.currentThread(); // 获取线程状态 Thread.State state = currThread.getState...(); } } } }); // 启动线程 thread.start(); // 获取线程状态 Thread.State state = thread.getState...lock.wait(); // 获取当前线程状态 Thread.State state = Thread.currentThread().getState...(); } } } }); // 启动线程 thread.start(); // 获取线程状态 Thread.State state = thread.getState
redux的主要API集中在createStore函数返回值中,以下这个迷你的redux只简单实现createStore、dispatch、subscribe、getState方法,如下: const...currentState = initialState; } let currentReducer = reducer; let listeners = []; return { getState...store.subscribe(function() { console.log('before2') }); store.dispatch({ type:'ADD' }); console.log(store.getState...()); store.dispatch({ type: 'ADD' }); console.log(store.getState()); store.dispatch({ type: 'DEL'...}); console.log(store.getState()); 运行结果: ?
store对象对外暴露了dispatch、getState、subscribe方法 store对象通过getState() 获取内部状态 initialState为 store 的初始状态,如果不传则为...You may then * call `getState()` to read the current state tree inside the callback....可以先看伪代码感受下,最终 store.getState() 返回的state,大概会是这么个样子{todos: xx, filter: xx}。...()); // state is: 读书,阅读,睡觉 actions.addTodo('看电影'); console.log('state is: ' + store.getState()); /...middlleware (redux-thunk),可以看到,chain的每个元素为如下形式的function 并且, 传入的 store.getState 为原始的 store.getState
main(String[] args) { Context context = new Context(new TreatGirlfriend()); context.getState...();//对待女朋友的状态 Context context1 = new Context(new TreatMother()); context1.getState();...} } abstract class SelfStrategy{ public abstract void getState(); //对待人地状态,对待不同人有不同实现 } class Context...() { strategy.getState(); } } class TreatGirlfriend extends SelfStrategy{ @Override...extends SelfStrategy{ @Override public void getState() { System.out.println("对待母亲地状态
(); console.log(state.counter.count); }); store.changeState({ ...store.getState(), info: {...这里需要理解的是 createStore,提供了 changeState,getState,subscribe 三个能力。...(); console.log(state.count); }); /*自增*/ store.changeState({ count: store.getState().count + 1 })...; /*自减*/ store.changeState({ count: store.getState().count - 1 }); /*我想随便改*/ store.changeState({...因为我们只允许你用 getState 方法!
领取专属 10元无门槛券
手把手带您无忧上云