2016-10-04 5 views
0

Nate Strauser의 상태 머신 (https://github.com/nate-strauser/meteor-statemachine)을 구현했습니다. 나는 그것의 상태를 DB에 성공적으로 저장하는 FSM을 얻지 만 여러 인스턴스를 추적하고있다. 필자의 예에서는 근로자의 근무 상태를 추적하고있다.Meteor State Machine

유성 시작시 시스템마다 상태를로드하려고합니다. 그런 다음 상태 머신 인스턴스에 대한 상태 변경 요청을 만들고 DB 문서의 상태를 업데이트하려고합니다 (변경이 허용되는 경우).

FSM 인스턴스를 실제 Shift 인스턴스와 어떻게 결합합니까? 나는 이것을 잘못된 방향으로 접근하고 있는가? 어떤 생각이라도 감사합니다. 어떤 국가를 선택할 수 있도록하는 transitionTo 방법을 추가 원래 상태 기계의 포크의 변화가

Meteor.startup(function() { 

var machineEvents = [ 
    { name: 'toggleduty', from: 'Off_Duty',  to: 'On_Duty_Idle' }, 
    { name: 'toggleduty', from: 'On_Duty_Idle', to: 'Off_Duty' }, 
    { name: 'toggleduty', from: 'On_Duty_Busy', to: 'Off_Duty_Busy' }, 
    { name: 'toggleduty', from: 'Off_Duty_Busy', to: 'On_Duty_Busy' }, 
    { name: 'togglebusy', from: 'On_Duty_Idle', to: 'On_Duty_Busy' }, 
    { name: 'togglebusy', from: 'On_Duty_Busy', to: 'On_Duty_Idle' }, 
    { name: 'togglebusy', from: 'Off_Duty_Busy', to: 'Off_Duty' }, 
    { name: 'start',  from: 'Init',   to: 'On_Duty_Idle' },]; 

var machineCallbacks = { 
    ontoggleduty: function(event, from, to, shift) { 
     console.log('Toggling Duty', shift); 
     Shifts.update(shift._id, {$set: { 'status':to }}); 
    }, 
    ontogglebusy: function(event, from, to, shift) { 
     console.log('Toggling Busy', shift); 
     Shifts.update(shift._id, {$set: { 'status':to }}); 
    }, 
}; 


var makeStateMachine = function(shift){ 
    console.log('new state machine generating'); 
    var stateMachine = StateMachine.create({ 
     initial: shift.status, 
     events: machineEvents, 
     callbacks: machineCallbacks 
    }); 
    switch (shift.state) { 
     case "Init": 
      console.log('Init to On_Duty_Idle',shift); 
      stateMachine.start(shift); 
      break; 
    } 
}; 

// function killStateMachine(shift){ // not sure how to kill the specific reference 
//  stateMachine = null; 
// } 

//look for new state machines 
Shifts.find({'status': 'Init'}).observe({ 
    added: makeStateMachine, 
    //removed: killStateMachine 
}); 

// In the mongo shell I trigger with db.statemachines.insert({_id:'driver1', state:'start'}) 

}); 

답변

0

- 내가 생각하는 당신이 데이터베이스에서 상태를 복원에서 원하는 것입니다. 나는 몇 가지 다른 민족을 통합 포크 (나는 그것의 릴리스를하지 않은 있지만) 당신은 내 REPO를 참조하는 프로젝트의 로컬 natestrauser의 패키지를 복제 할 수

https://github.com/mikkelking/javascript-state-machine

을 변경해야합니다. 나는 나의 변화가 안정적 일 때 어떤 시점에서 풀 요청을하려고 의도하고있다.

관련 문제