Titanium JIRA Archive
Appcelerator Community (AC)

[AC-3398] Ti.App.Properties.getObject(property,default);

GitHub Issuen/a
TypeImprovement
Priorityn/a
StatusClosed
ResolutionNeeds more info
Resolution Date2016-03-30T18:15:01.000+0000
Affected Version/sAppcelerator Studio 4.5.0
Fix Version/sn/a
Componentsn/a
Labelsfeedback
ReporterSean MacLachlan
AssigneeShak Hossain
Created2016-03-21T23:02:45.000+0000
Updated2016-03-30T18:15:01.000+0000

Description

var user = Ti.App.Properties.getObject('user', accounts.createUser());

This is calling the default method even though property exists.

Comments

  1. Nazmus Salahin 2016-03-22

    Hello, I have tested the following code and got expected result. Default method is not called when property exists. *Code:*
       var defaultObject = 'Default';
       var realObject = 'RealData';
       Ti.App.Properties.setObject('testName', realObject);
       var obj = Ti.App.Properties.getObject('testName', defaultFunction());
       Ti.API.info(obj.toString());
       
       function defaultFunction() {
       	return defaultObject;
       }
       
    *Console Output*
       [INFO] :   RealData
       
    *Expected Result:* Shows existing property rather than default property when exists . *Actual Result:* Existing property is shown rather than default property when exists. *Environment*: *Device info:* Nexux7 (android 6.0.1) *Node.js Version:* 0.12.7 *npm Version:* 2.11.3 *Titanium SDKs:* 5.2.0 and 5.1.2.GA *Java Development Kit Version:* 1.8.0_73 *Titanium CLI Version:* 5.0.5 *Appcelerator CLI Version:* 5.2.0 *Appcelerator Studio:* 4.4.0.201511241829
  2. Sharif AbuDarda 2016-03-22

    Hello, Can you be a little more specific and explain what you are trying to do and what you are expecting to happen? Please provide a complete test code which you think demonstrate the unexpected behavior. Also please provide the complete steps to follow. Please provide your platform information. Thanks.
  3. Sean MacLachlan 2016-03-22

    var accounts = { // Create a new anonymous user createUser: function createUser(){ Ti.API.log("Creating new user"); accounts.clearCache(); return require('user'); }, loadUser: function loadUser(){ Ti.API.log('accounts.js : loadUser - user cache ' + JSON.stringify(Ti.App.Properties.getObject('user'))); // This should work but create user is being called everytime, not just on undefined Alloy.Globals.user = Ti.App.Properties.getObject('user',accounts.createUser()); }, // Caches user changes and Uploads user settings to Orchestrate updateUser: function updateUser(){ Ti.API.log("accounts.js : updateUser - cache " + JSON.stringify(Alloy.Globals.user)); Ti.App.Properties.setObject('user',Alloy.Globals.user); Ti.API.log('accounts.js : updateUser - user cache ' + JSON.stringify(Ti.App.Properties.getObject('user'))); }, }; module.exports = accounts; My logging shows that I'm calling loadUser and the user object isn't empty but it is calling createUser [INFO] : accounts.js : loadUser - user cache {"location":{"useGPS":false,"city":"Boise","distance":"20.0","address":"Boise, ID, USA","success":true},"userEmail":"",status":"New","accountType":"anonymous"} [INFO] : Creating new user [DEBUG] : Loading: /Users/Sean/Library/Developer/CoreSimulator/Devices/5A3586F1-25C4-4F86-A169-0BB19D1FE96E/data/Containers/Bundle/Application/CF83D2E7-0E59-46DF-A617-3F5CA54B4A93/relevent.app/user.js, Resource: user_js [INFO] : accounts.js : loadUser - loaded {"location":{"distance":20,"city":"Boise","useGPS":false,"address":"Boise, ID"},"userEmail":"",status":"Created","accountType":"anonymous"} Some of the logging and library methods were removed
  4. Sharif AbuDarda 2016-03-23

    Hello, The code you have provided has additional components and it isn't clear. Also, you haven't provided the complete steps. Please strip out any code from sample code that does not relate to the bug. Make it as minimalistic as you can. Only add code in order to show the issue, and keep out other things. Please provide a complete test code which you think demonstrate the unexpected behavior. Also please provide the complete steps to follow. Please provide your platform information. Follow the instruction http://docs.appcelerator.com/platform/latest/#!/guide/How_to_Submit_a_Bug_Report-section-29004732_HowtoSubmitaBugReport-CreatingaJIRAticket. Thanks.

JSON Source