Nativescript 2.2.0 更新后引发的未处理异常
Unhanded Exception thrown following Nativescript 2.2.0 update
我刚刚更新到 Nativescript 2.2.0,一切都构建良好并且在我的大部分应用程序中运行良好。加载特定视图时,尽管我得到了以下未处理的异常以及堆栈跟踪。这在更新核心平台和模块之前不会发生。当我搜索堆栈跟踪中提到的 'disableNotifications' 属性 时,我在我的项目中找不到任何此类内容。在做了一些挖掘之后似乎与核心框架有些不同,任何人有什么想法吗?
编辑:这是核心可观察模块中发生错误的实际代码块。他们是否删除了按以下方式添加属性的功能 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];
};
以下是我倾向于在我的视图模型中实例化我的 Observable 的方式:
var model = new Observable({
measurements: new ObservableArray([]),
recentMeasurement: {},
notificationsEnabled: appSettings.getBoolean('notificationsEnabled', true),
patientFirstName: "",
patientLastName: "",
units: "",
hasMultipleConnections: true
});
另一个例子
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')
});
原始堆栈跟踪
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:
所以,在我的例子中,问题似乎是由于嵌套的 Observable。通过删除嵌套的可观察对象,不再抛出异常:
老办法
var model = new Observable({
measurements: new ObservableArray([]),
recentMeasurement: {},
notificationsEnabled: appSettings.getBoolean('notificationsEnabled', true),
patientFirstName: "",
patientLastName: "",
units: "",
hasMultipleConnections: true
});
新方式
var model = new Observable({
measurements: [],
recentMeasurement: {},
notificationsEnabled: appSettings.getBoolean('notificationsEnabled', true),
patientFirstName: "",
patientLastName: "",
units: "",
hasMultipleConnections: true
});
此更改似乎还导致我安装和使用的一些插件出现问题。你可以看到这个提到here on Github
我刚刚更新到 Nativescript 2.2.0,一切都构建良好并且在我的大部分应用程序中运行良好。加载特定视图时,尽管我得到了以下未处理的异常以及堆栈跟踪。这在更新核心平台和模块之前不会发生。当我搜索堆栈跟踪中提到的 'disableNotifications' 属性 时,我在我的项目中找不到任何此类内容。在做了一些挖掘之后似乎与核心框架有些不同,任何人有什么想法吗?
编辑:这是核心可观察模块中发生错误的实际代码块。他们是否删除了按以下方式添加属性的功能 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];
};
以下是我倾向于在我的视图模型中实例化我的 Observable 的方式:
var model = new Observable({
measurements: new ObservableArray([]),
recentMeasurement: {},
notificationsEnabled: appSettings.getBoolean('notificationsEnabled', true),
patientFirstName: "",
patientLastName: "",
units: "",
hasMultipleConnections: true
});
另一个例子
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')
});
原始堆栈跟踪
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:
所以,在我的例子中,问题似乎是由于嵌套的 Observable。通过删除嵌套的可观察对象,不再抛出异常:
老办法
var model = new Observable({
measurements: new ObservableArray([]),
recentMeasurement: {},
notificationsEnabled: appSettings.getBoolean('notificationsEnabled', true),
patientFirstName: "",
patientLastName: "",
units: "",
hasMultipleConnections: true
});
新方式
var model = new Observable({
measurements: [],
recentMeasurement: {},
notificationsEnabled: appSettings.getBoolean('notificationsEnabled', true),
patientFirstName: "",
patientLastName: "",
units: "",
hasMultipleConnections: true
});
此更改似乎还导致我安装和使用的一些插件出现问题。你可以看到这个提到here on Github