本文整理汇总了TypeScript中mobx-state-tree.getSnapshot函数的典型用法代码示例。如果您正苦于以下问题:TypeScript getSnapshot函数的具体用法?TypeScript getSnapshot怎么用?TypeScript getSnapshot使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getSnapshot函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: test
test("responds with current state", t => {
const { track, plugin } = createMstPlugin()
const user = TestUserModel.create()
track(user)
plugin.onCommand(INBOUND)
t.deepEqual(STATE, getSnapshot(user))
})
开发者ID:TheIdhem,项目名称:reactotron,代码行数:7,代码来源:restore.test.ts
示例2: backup
// --- Reactotron Hooks ---------------------------------
/**
* A backup of state has been requested. Lets serialize the current
* state and send it up to the app.
*
* @param command A reactotron command.
*/
function backup(command: any) {
const trackedNode = trackedNodes[command.mstNodeName || "default"]
if (trackedNode && trackedNode.node) {
const state = getSnapshot(trackedNode.node)
reactotron.send("state.backup.response", { state })
}
}
开发者ID:nick121212,项目名称:reactotron,代码行数:15,代码来源:reactotron-mst.ts
示例3:
action => {
if (applyingSnapshot) return
const copy: any = {}
copy.type = action.name
if (action.args) action.args.forEach((value, index) => (copy[index] = value))
remotedev.send(copy, mst.getSnapshot(model))
},
开发者ID:lelandyolo,项目名称:mobx-state-tree,代码行数:7,代码来源:redux.ts
示例4: subscribe
/**
* Subscribes to some paths in state. Allows the user to track a subset of
* data within the state that will be sent to them every time it changes.
*
* @param command The command received from the reactotron app.
*/
function subscribe(command: any) {
const trackedNode = trackedNodes[command.mstNodeName || "default"]
const paths: string[] = (command && command.payload && command.payload.paths) || []
if (trackedNode && trackedNode.node && paths) {
subscriptions = uniq(flatten(paths))
const state = getSnapshot(trackedNode.node)
sendSubscriptions(state)
}
}
开发者ID:nick121212,项目名称:reactotron,代码行数:15,代码来源:reactotron-mst.ts
示例5: connectReduxDevtools
export const connectReduxDevtools = function connectReduxDevtools(remoteDevDep: any, model: any) {
// Connect to the monitor
const remotedev = remoteDevDep.connectViaExtension({ name: mst.getType(model).name })
let applyingSnapshot = false
// Subscribe to change state (if need more than just logging)
remotedev.subscribe((message: any) => {
if (message.type === "DISPATCH") {
handleMonitorActions(remotedev, model, message)
}
})
const initialState = mst.getSnapshot(model)
remotedev.init(initialState)
// Send changes to the remote monitor
mst.onAction(
model,
action => {
if (applyingSnapshot) return
const copy: any = {}
copy.type = action.name
if (action.args) action.args.forEach((value, index) => (copy[index] = value))
remotedev.send(copy, mst.getSnapshot(model))
},
true
)
function handleMonitorActions(remotedev: any, model: any, message: any) {
switch (message.payload.type) {
case "RESET":
applySnapshot(model, initialState)
return remotedev.init(initialState)
case "COMMIT":
return remotedev.init(mst.getSnapshot(model))
case "ROLLBACK":
return remotedev.init(remoteDevDep.extractState(message))
case "JUMP_TO_STATE":
case "JUMP_TO_ACTION":
applySnapshot(model, remoteDevDep.extractState(message))
return
case "IMPORT_STATE":
const nextLiftedState = message.payload.nextLiftedState
const computedStates = nextLiftedState.computedStates
applySnapshot(model, computedStates[computedStates.length - 1].state)
remotedev.send(null, nextLiftedState)
return
default:
}
}
function applySnapshot(model: any, state: any) {
applyingSnapshot = true
mst.applySnapshot(model, state)
applyingSnapshot = false
}
}
开发者ID:lelandyolo,项目名称:mobx-state-tree,代码行数:57,代码来源:redux.ts
示例6: requestValues
/**
* Gets the current value located at the path within the state tree.
*
* @param command The command received from the reactotron app.
*/
function requestValues(command: any) {
const trackedNode = trackedNodes[command.mstNodeName || "default"]
const atPath: string = (command && command.payload && command.payload.path) || []
if (trackedNode && trackedNode.node && atPath) {
const state = getSnapshot(trackedNode.node)
if (isNilOrEmpty(atPath)) {
reactotron.stateValuesResponse(null, state)
} else {
reactotron.stateValuesResponse(atPath, dotPath(atPath, state))
}
}
}
开发者ID:nick121212,项目名称:reactotron,代码行数:17,代码来源:reactotron-mst.ts
示例7: addUndoState
.actions(self => {
let targetStore: any
let snapshotDisposer: any
let skipNextUndoState = false
return {
addUndoState(todos: any) {
if (skipNextUndoState) {
// skip recording if this state was caused by undo / redo
skipNextUndoState = false
return
}
self.history.splice(self.undoIdx + 1)
self.history.push(todos)
self.undoIdx = self.history.length - 1
},
afterCreate() {
targetStore = self.targetPath
? resolvePath(self, self.targetPath)
: getEnv(self).targetStore
if (!targetStore)
throw new Error(
"Failed to find target store for TimeTraveller. Please provide `targetPath` property, or a `targetStore` in the environment"
)
// TODO: check if targetStore doesn't contain self
// if (contains(targetStore, self)) throw new Error("TimeTraveller shouldn't be recording itself. Please specify a sibling as taret, not some parent")
// start listening to changes
snapshotDisposer = onSnapshot(targetStore, snapshot =>
(self as any).addUndoState(snapshot)
)
// record an initial state if no known
if (self.history.length === 0) (self as any).addUndoState(getSnapshot(targetStore))
},
beforeDestroy() {
snapshotDisposer()
},
undo() {
self.undoIdx--
skipNextUndoState = true
applySnapshot(targetStore, self.history[self.undoIdx])
},
redo() {
self.undoIdx++
skipNextUndoState = true
applySnapshot(targetStore, self.history[self.undoIdx])
}
}
})
开发者ID:lelandyolo,项目名称:mobx-state-tree,代码行数:48,代码来源:time-traveller.ts
示例8: handleMonitorActions
function handleMonitorActions(remotedev: any, model: any, message: any) {
switch (message.payload.type) {
case "RESET":
applySnapshot(model, initialState)
return remotedev.init(initialState)
case "COMMIT":
return remotedev.init(mst.getSnapshot(model))
case "ROLLBACK":
return remotedev.init(remoteDevDep.extractState(message))
case "JUMP_TO_STATE":
case "JUMP_TO_ACTION":
applySnapshot(model, remoteDevDep.extractState(message))
return
case "IMPORT_STATE":
const nextLiftedState = message.payload.nextLiftedState
const computedStates = nextLiftedState.computedStates
applySnapshot(model, computedStates[computedStates.length - 1].state)
remotedev.send(null, nextLiftedState)
return
default:
}
}
开发者ID:lelandyolo,项目名称:mobx-state-tree,代码行数:22,代码来源:redux.ts
注:本文中的mobx-state-tree.getSnapshot函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论