Come ofObjectChanges è costruito su Object.observe() che è obsoleto (https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/observe) Sto cercando un'alternativa per la visione di modifiche alle proprietà dell'oggetto. Qualcuno sa di uno?rxjs ofObjectChanges obsoleti
5
A
risposta
2
Forse usando un proxy è un'opzione, anche se è necessario sostituire l'oggetto originale
const { Subject } = require('rxjs');
// Take an object, and return a proxy with an 'observation$' stream
const toObservableObject = targetObject => {
const observation$ = new Subject();
return new Proxy(targetObject, {
set: (target, name, value) => {
const oldValue = target[name];
const newValue = value;
target[name] = value;
observation$.next({ name, oldValue, newValue });
},
get: (target, name) => name == 'observation$' ? observation$ : target[name]
});
}
const observableObject = toObservableObject({ });
observableObject.observation$
.filter(modification => modification.name == 'something')
.subscribe(({ name, oldValue, newValue }) => console.log(`${name} changed from ${oldValue} to ${newValue}`));
observableObject.something = 1;
observableObject.something = 2;
L'uscita
something changed from undefined to 1
something changed from 1 to 2
Cercare Proxy nelle versioni nodo corrente tabella compatibilità ha appoggio) https://kangax.github.io/compat-table/es6/
E documentazione del proxy a https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Proxy
Problemi correlati
- 1. Ricerca dell'analogo del metodo RxJs ofObjectChanges in Angular 2
- 2. Node.js oggetti obsoleti-chiavi
- 3. ottenere errori rxjs quando si fa riferimento all'ultima versione rxjs
- 4. Rxjs durante l'osservazione degli aggiornamenti degli oggetti e delle modifiche
- 5. appSettings vs applicationSettings. appSettings obsoleti?
- 6. Elementi obsoleti nell'elenco tabella pivot
- 7. Messaggi registro raccolta dati obsoleti
- 8. Gli IFrame (HTML) sono obsoleti?
- 9. Consigli obsoleti per l'ottimizzazione Java
- 10. Redux & RxJS, eventuali somiglianze?
- 11. RXJS: rimbalzo aggregato
- 12. shareReplay in RxJS 5
- 13. Riduzione RxJS non continua
- 14. Come usare RxJs distinctUntilChanged?
- 15. RxJS - Indicatore caricamento
- 16. Impaginazione osservabile RxJs
- 17. RxJS distinctUntilChanged - compendio oggetto
- 18. Promise .all() con RxJS
- 19. Uso Rxjs fasci UMD
- 20. Angular2 Rxjs 404 errore
- 21. Chaining osservabili in RxJS
- 22. RxJs ottenere valore da osservabile
- 23. Raccogli RxJS Observable to Array
- 24. RxJS 5.0 meccanismo "do while"
- 25. Sequenza RxJS equivoca a promise.then()?
- 26. Promise.all comportamento con RxJS Observables?
- 27. RxJS abbonamenti multipli per Observable.Interval
- 28. Angular2 rxjs manca metodo observable.interval
- 29. Sottoscrittori RxJs, passando valori nulli?
- 30. Soppressione di avvisi obsoleti in VB.NET