Unhanded Exception thrown following Nativescript 2.2.0 update

限于喜欢 提交于 2019-12-13 06:59:48

问题


I just updated to Nativescript 2.2.0, everything built fine and runs fine through most of my app. When loading a specific view though I get the below unhandled exception along with the stack trace. This was not occuring before updating the core platform and modules. When I search for the 'disableNotifications' property mentioned in the stack trace I find nothing of the sort in my project. After doing some digging seems to be apart of the core framework some where, any body have any ideas?

EDIT: Here is the actual chunk of code where the error is occuring in the core observable module. Have they removed the ability to add properties in the following way var model = new Observable({propName: 'value'});?

Observable.js code where exception is thrown:
    Observable.prototype._setCore = function (data) {
        this.disableNotifications[data.propertyName] = true;
        var newValue = WrappedValue.unwrap(data.value);
        this[data.propertyName] = newValue;
        delete this.disableNotifications[data.propertyName];
    };

Here is how I tend to instantiate my Observables within my view models:

var model = new Observable({
    measurements: new ObservableArray([]),
    recentMeasurement: {},
    notificationsEnabled: appSettings.getBoolean('notificationsEnabled', true),
    patientFirstName: "",
    patientLastName: "",
    units: "",
    hasMultipleConnections: true
});

Another Example

var model = new Observable({        
    countries:  new ValueList([
        { ValueMember: "FR", DisplayMember: L('france') },
        { ValueMember: "DE", DisplayMember: L('germany') },
        { ValueMember: "IT", DisplayMember: L('italy') },
        { ValueMember: "NL", DisplayMember: L('netherlands') },
        { ValueMember: "ES", DisplayMember: L('spain') },
        { ValueMember: "SE", DisplayMember: L('sweden') },
        { ValueMember: "GB", DisplayMember: L('unitedkingdom') }]),  
    selectedCountry: 0,
    countryPlaceholder: L('select_country')
});

Original Stack Trace

com.tns.NativeScriptException:  Calling js method onTouch failed

TypeError: Cannot set property 'disableNotifications' of undefined
File: "/data/data/org.nativescript.CareGiver/files/app/tns_modules/ui/gestures/gestures.js", line: 97, column: 40

StackTrace:   Frame: function:'Observable._setCore',
file:'/data/data/org.nativescript.CareGiver/files/app/tns_modules/data/observable/observable.js',
line: 136, column: 54     Frame: function:'Observable.set',
file:'/data/data/org.nativescript.CareGiver/files/app/tns_modules/data/observable/observable.js',
line: 129, column: 14     Frame: function:'Observable',
file:'/data/data/org.nativescript.CareGiver/files/app/tns_modules/data/observable/observable.js',
line: 50, column: 26  Frame: function:'Observable',
file:'/data/data/org.nativescript.CareGiver/files/app/tns_modules/data/observable/observable.js',
line: 47, column: 38  Frame: function:'MeasurementViewModel',
file:'/data/data/org.nativescript.CareGiver/files/app/models/measurement-view-model.js',
line: 16, column:
file:'/data/data/org.nativescript.CareGiver/files/app/models/measurement-view-model.js',
line: 16, column:

回答1:


So, in my case the problem seemed to be due to having nested Observables. By removing the nested observable the exception was no longer being thrown:

Old Way

var model = new Observable({
    measurements: new ObservableArray([]),
    recentMeasurement: {},
    notificationsEnabled: appSettings.getBoolean('notificationsEnabled', true),
    patientFirstName: "",
    patientLastName: "",
    units: "",
    hasMultipleConnections: true
});

New Way

var model = new Observable({
    measurements: [],
    recentMeasurement: {},
    notificationsEnabled: appSettings.getBoolean('notificationsEnabled', true),
    patientFirstName: "",
    patientLastName: "",
    units: "",
    hasMultipleConnections: true
});

This change also seems to be causing some problems with a few of the plugins I have installed and am using. You can see this mentioned here on Github



来源:https://stackoverflow.com/questions/38884661/unhanded-exception-thrown-following-nativescript-2-2-0-update

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!