I am trying to create a timed buffer that only stores 1 item in a mobx observable. I call a function in store that creates a timer so that no other item can be saved in the store until the timer is complete. However the observable seems to be overriding this, if thats even possible.
I am attempting 2 things ( The timed buffer, The array size restrictor )
Do observables override the standard javascript array methods/functions?
On the output of the observable in React I see a huge array and not restricted to length of 1.
addTourList(node);
Here is my store.js mobx class.
import { action, autorun, observable, computed, toJS } from 'mobx';
import { onError } from 'mobx-react';
class MainStore {
@observable
tourList = [];
tourBuffer = null;
addTourList(node) {
if(node.loc == undefined){
return false;
}else{
if(this.tourBuffer == null){
this.buffer = function(){
console.log('END TOUR BUFFER TIMER!');
this.tourBuffer = null;
}
this.updateTourList(node)
console.log('START TOUR BUFFER TIMER!');
this.tourBuffer = setTimeout( this.buffer.bind(this), 4000);
}else{
console.log("TOUR ANIMATION BUSY");
}
return true;
}
}
@action
updateTourList(node) {
var maxStoreData = 1;
this.tourList.unshift(node);
this.tourList.slice(0, maxStoreData);
}
}
const store = (window.store = new MainStore());
onError(error => {
console.log('STORE ERROR:', error);
});
export default store;