Skip to content

Instantly share code, notes, and snippets.

@carlosdelfino
Created July 31, 2017 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlosdelfino/5af9e8639666def43f347e1cd6a7dcff to your computer and use it in GitHub Desktop.
Save carlosdelfino/5af9e8639666def43f347e1cd6a7dcff to your computer and use it in GitHub Desktop.
Problema relativo a instanciação com ES6 no NativeScript
Successfully synced application br.com.ritech.MobileECG.mobile.client on device LQ4325B15008.
JS: Handler onNavigatingTo navigatingTo
JS: 2017-07-31T14:20:13.788Z Debug: Modulo aplicação carregado e TraceManager inicializado!
JS: 2017-07-31T14:20:13.806Z Debug: Obtendo Instância do MobileManager!
JS: 2017-07-31T14:20:13.807Z Debug: Obtendo Instância do MobileManager!
JS: 2017-07-31T14:20:13.808Z Debug: Inicializando Aplicação
JS: 2017-07-31T14:20:13.808Z Debug: APP Version: 0.0.003
JS: 2017-07-31T14:20:13.808Z Debug: Managers Version: 0.0.1
JS: 2017-07-31T14:20:16.486Z Debug: Carreando conteudo página principal
JS: 2017-07-31T14:20:16.487Z Debug: Image<logo>@file:///app/pages/home/home.xml:26:10;
JS: 2017-07-31T14:20:16.726Z Debug: Carregando Página:home
JS: 2017-07-31T14:20:18.253Z Debug: Animação finalizada.
JS: 2017-07-31T14:20:20.416Z Debug: Navegando: [object Object]
JS: 2017-07-31T14:20:20.416Z Debug: Contexto: undefined
JS: 2017-07-31T14:20:20.417Z Dump: === dump(): object is 'null' ===
JS: 2017-07-31T14:20:20.421Z Debug: Página anterior: home
JS: 2017-07-31T14:20:20.422Z Debug: Usando parametro 'dest'.
JS: 2017-07-31T14:20:20.424Z Debug: Navegando para a página: login
JS: 2017-07-31T14:20:20.426Z Dump: === dump(): dumping members ===
JS: {
JS: "moduleName": "pages/login/login",
JS: "animated": true
JS: }
JS: === dump(): dumping function and properties names ===
JS: === dump(): finished ===
JS: 2017-07-31T14:20:20.512Z Debug: Criando LoginPage!
JS: 2017-07-31T14:20:20.513Z Debug: Usando os dados iniciais:
JS: 2017-07-31T14:20:20.514Z Dump: === dump(): dumping members ===
JS: {
JS: "email": "test@test.com",
JS: "password": "test"
JS: }
JS: === dump(): dumping function and properties names ===
JS: === dump(): finished ===
JS: 2017-07-31T14:20:20.515Z Debug: UserLoginModel, criado!
JS: 2017-07-31T14:20:20.515Z Dump: === dump(): dumping members ===
JS: {
JS: "_observers": {}
JS: }
JS: === dump(): dumping function and properties names ===
JS: get()
JS: set()
JS: on()
JS: off()
JS: addEventListener()
JS: removeEventListener()
JS: notify()
JS: notifyPropertyChange()
JS: hasListeners()
JS: _createPropertyChangeData()
JS: _emit()
JS: _getEventList()
JS: _indexOfListener()
JS: === dump(): finished ===
JS: 2017-07-31T14:20:21.197Z Debug: Carregando a Página de login
JS: 2017-07-31T14:20:21.197Z Debug: bindingContext
JS: 2017-07-31T14:20:21.198Z Dump: === dump(): object is 'null' ===
JS: 2017-07-31T14:20:21.198Z Debug: Página de login carregada
JS: 2017-07-31T14:20:21.259Z Debug: Carregando Página:login
@carlosdelfino
Copy link
Author

Adicionado o dump do "this", descobri que está fazendo referencia ao callback do método e não a instancia da classe do método:

Successfully transferred login.js.
Refreshing application...
Successfully synced application br.com.ritech.MobileECG.mobile.client on device LQ4325B15008.
JS: Handler onNavigatingTo navigatingTo
JS: 2017-07-31T14:25:05.506Z Debug: Modulo aplicação carregado e TraceManager inicializado!
JS: 2017-07-31T14:25:05.523Z Debug: Obtendo Instância do MobileManager!
JS: 2017-07-31T14:25:05.524Z Debug: Obtendo Instância do MobileManager!
JS: 2017-07-31T14:25:05.525Z Debug: Inicializando Aplicação
JS: 2017-07-31T14:25:05.525Z Debug: APP Version: 0.0.003
JS: 2017-07-31T14:25:05.525Z Debug: Managers Version: 0.0.1
JS: 2017-07-31T14:25:08.507Z Debug: Carreando conteudo página principal
JS: 2017-07-31T14:25:08.508Z Debug: Image@file:///app/pages/home/home.xml:26:10;
JS: 2017-07-31T14:25:08.723Z Debug: Carregando Página:home
JS: 2017-07-31T14:25:10.153Z Debug: Navegando: [object Object]
JS: 2017-07-31T14:25:10.154Z Debug: Contexto: undefined
JS: 2017-07-31T14:25:10.155Z Dump: === dump(): object is 'null' ===
JS: 2017-07-31T14:25:10.158Z Debug: Página anterior: home
JS: 2017-07-31T14:25:10.158Z Debug: Usando parametro 'dest'.
JS: 2017-07-31T14:25:10.159Z Debug: Navegando para a página: login
JS: 2017-07-31T14:25:10.160Z Dump: === dump(): dumping members ===
JS: {
JS: "moduleName": "pages/login/login",
JS: "animated": true
JS: }
JS: === dump(): dumping function and properties names ===
JS: === dump(): finished ===
JS: 2017-07-31T14:25:10.240Z Debug: Criando LoginPage!
JS: 2017-07-31T14:25:10.241Z Debug: Usando os dados iniciais:
JS: 2017-07-31T14:25:10.241Z Dump: === dump(): dumping members ===
JS: {
JS: "email": "test@test.com",
JS: "password": "test"
JS: }
JS: === dump(): dumping function and properties names ===
JS: === dump(): finished ===
JS: 2017-07-31T14:25:10.242Z Debug: UserLoginModel, criado!
JS: 2017-07-31T14:25:10.242Z Dump: === dump(): dumping members ===
JS: {
JS: "_observers": {}
JS: }
JS: === dump(): dumping function and properties names ===
JS: get()
JS: set()
JS: on()
JS: off()
JS: addEventListener()
JS: removeEventListener()
JS: notify()
JS: notifyPropertyChange()
JS: hasListeners()
JS: _createPropertyChangeData()
JS: _emit()
JS: _getEventList()
JS: _indexOfListener()
JS: === dump(): finished ===
JS: 2017-07-31T14:25:10.501Z Debug: Animação finalizada.
JS: 2017-07-31T14:25:10.793Z Debug: Carregando a Página de login
JS: 2017-07-31T14:25:10.793Z Debug: bindingContext
JS: 2017-07-31T14:25:10.794Z Dump: === dump(): dumping members ===
JS: {
JS: "callback": "callback()contentLoaded(args) {\n\t\tmyTrace.write("Carregando a Página de login");\n\t\tlet page = args.object;\n\t\tif (page.ios) {\n\t\t\tlet navigationBar = frameModule.topmost().ios.controller.navigationBar;\n\t\t\tnavigationBar.barStyle = UIBarStyle.UIBarStyleBlack;\n\t\t}\n\t\tmyTrace.write("bindingContext");\n\t\tlet model = this.userViewModel;\n\t\tpage.bindingContext = model;\n\t\tmyTrace.dump(this);\n\t\tmyTrace.dump(model);\n\t\tmyTrace.write("Página de login carregada");\n\t}"
JS: }
JS: === dump(): dumping function and properties names ===
JS: callback()
JS: === dump(): finished ===
JS: 2017-07-31T14:25:10.794Z Dump: === dump(): object is 'null' ===
JS: 2017-07-31T14:25:10.794Z Debug: Página de login carregada
JS: 2017-07-31T14:25:10.865Z Debug: Carregando Página:login

@carlosdelfino
Copy link
Author

	// Place any code you want to run when the home page loads here.
	contentLoaded = (args) =>{
		myTrace.write("Carregando a Página de login");
		let page = args.object;
		if (page.ios) {
			let navigationBar = frameModule.topmost().ios.controller.navigationBar;
			navigationBar.barStyle = UIBarStyle.UIBarStyleBlack;
		}
		myTrace.write("bindingContext");
      myTrace.dump(args);
      myTrace.dump(this);
      let model = this.userViewModel;
      myTrace.dump(model);
		page.bindingContext = model;
		myTrace.write("Página de login carregada");
	}

@carlosdelfino
Copy link
Author

O LoginPage (login.js) ficou assim:

var topmost = require("ui/frame").topmost;
var frameModule = require("ui/frame");
var dialogsModule = require("ui/dialogs");

var listViewModule = require("nativescript-telerik-ui-pro/listview");
var drawerModule = require("nativescript-telerik-ui-pro/sidedrawer");
var calendarModule = require("nativescript-telerik-ui-pro/calendar");
var chartModule = require("nativescript-telerik-ui-pro/chart");
var dataFormModule = require("nativescript-telerik-ui-pro/dataform");
var chartModule = require("nativescript-telerik-ui-pro/gauges");
var dataFormModule = require("nativescript-telerik-ui-pro/autocomplete");

var myTrace = require("/managers/trace-manager/trace-manager").getInstance();
var BasePage = require("
/pages/fun-base-page");

var UserViewModel = require("~/view-models/user-view-model");

var model = new UserViewModel({
email : "test@test.com",
password : "test"
});

class LoginPage extends BasePage{

/**
* Constructor: TraceManager
*
*/
constructor(){
super();
myTrace.write("Criando LoginPage!");

	myTrace.write("UserLoginModel, criado!");
	myTrace.dump(this.userViewModel);
}

signIn(args) {
myTrace.write("Efetuando o Login!");

	model.login().
	then(() => {
		myTrace.write("Login ok");
		myTrace.write("Navegando para página de ECGs");
		this.navigate("ecg");
	}).
	catch((error) => {
			myTrace.write(error);
			if (error == UserViewModel.InvalidEmail) {
				dialogsModule.alert({
					message : error.msgCode,
					okButtonText : "OK"
				})
			} else {
				dialogsModule.alert({
					message : "Seu Cadastro não foi encontrado, verifique seus dados, ou faça seu cadastro clicando em registro.",
					okButtonText : "OK"
				});
			}
			return Promise.reject();
		});
};
  contentLoaded(args){
  		myTrace.write("Carregando a Página de login");
  		let page = args.object;
  		if (page.ios) {
  			let navigationBar = frameModule.topmost().ios.controller.navigationBar;
  			navigationBar.barStyle = UIBarStyle.UIBarStyleBlack;
  		}
  		myTrace.write("bindingContext");
  		page.bindingContext = model;
  		myTrace.write("Página de login carregada");
  	}

};

module.exports = new LoginPage();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment