[TIMOB-5167] iOS: Immutable objects on Window object
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Low |
Status | Closed |
Resolution | Won't Do |
Resolution Date | 2020-01-09T19:22:56.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | iOS |
Labels | core |
Reporter | Matthew O'Riordan |
Assignee | Ingo Muschenetz |
Created | 2011-08-16T14:51:19.000+0000 |
Updated | 2020-01-09T19:22:56.000+0000 |
Description
When you attach an object to a Window on iOS the object is immutable, yet on Android it works fine. For example, win.myCustomObject = { id: val } works as expected. However, when you then try and change a value within that object, the changes are never made i.e. win.myCustomObject.id = newVal, the id stays the same.
Code example requires two files:
var win = Ti.UI.createWindow({
backgroundColor: '#000',
url: 'window_object_win.js',
layout:'vertical'
});
win.data = {
text: 'Initialized'
};
win.open();
win.addEventListener('modifyData', function() {
win.data.text = 'This should be updated if this object is mutable';
win.fireEvent('dataUpdated');
});
win.addEventListener('replaceData', function() {
win.data = { text: 'If the data has changed now then replacing the entire data object works ' };
win.fireEvent('dataUpdated');
});
var modifyButton = Ti.UI.createButton({
title: 'Modify window .data object',
top: 60,
width: 250,
height: 80
});
var replaceButton = Ti.UI.createButton({
title: 'Replace window .data object',
top: 60,
width: 250,
height: 80
});
var label = Ti.UI.createLabel({
color: '#FFF',
top: 20,
height: 200
});
Ti.UI.currentWindow.add(modifyButton);
Ti.UI.currentWindow.add(replaceButton);
Ti.UI.currentWindow.add(label);
modifyButton.addEventListener('click', function() {
Ti.UI.currentWindow.fireEvent('modifyData');
});
replaceButton.addEventListener('click', function() {
Ti.UI.currentWindow.fireEvent('replaceData');
});
var counter = 0;
var updateLabelFromData = function() {
label.text = 'Text (' + counter++ + ' presses) = ' + Ti.UI.currentWindow.data.text;
};
Ti.UI.currentWindow.addEventListener('dataUpdated', updateLabelFromData);
updateLabelFromData();
To replicate this issue with this code example, load up the app, click on the bottom button (to modify values) and you will see that the value does not change. However, if you click on the button above that which replaces the entire object on the window, it works fine. On Android both buttons work as expected.
Matthew Can you see if there are any significant messages output to the log, and include them in your ticket in a code block, if you do? Many thanks
There aren't any messages related to this code.
I get this same issue when passing variables as part of a window AND when using Ti.App. I do something like: var someObject = {}; Ti.App.refToSomeObject = someObject; If I make changes to someObject in say a callback from an HTTP request and then another window accesses Ti.App.refToSomeObject, the changes aren't propagated.
Someone else has this same problem here: http://developer.appcelerator.com/question/65211/data-between-contexts-reference-vs-titaniumappproperties-#answer-129821
I found an issue in the support related to this: http://support.appcelerator.com/tickets/XIY-29136-551/report In case you can't see it, Nolan Wright says: "...attach properties to your window objects as you create them. the downside here is that each one is a copy so they are not the same variable - i.e., a change in one will not be reflected in the others."
@James - Please let me know the SDK version you are using.
This is caused by long-standing critical bug TIMOB-2392, which requires a significant investment in changing the iOS platform internals.
It has been decided that this issue should be closed as “Won’t do.” This issue is out of date with our current supported SDK release (7.5.2.GA as of the date of closure), and out of date with mobile OS versions. Updating, or creating code may not reproduce the issue reported, or be a valid test case. If community members feel that the issue is still valid, please create a new ticket. Please reference this closed ticket number, include SDK used, comments, and code that demonstrates/reproduces the issue.