Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My observations so far on Android #2

Open
zabojad opened this issue Feb 13, 2019 · 10 comments
Open

My observations so far on Android #2

zabojad opened this issue Feb 13, 2019 · 10 comments

Comments

@zabojad
Copy link

zabojad commented Feb 13, 2019

I've tested on Android and the issue is the same.

I think that RNN enables hot reload only for React Component.

I've replaced Scene1.js with a ES6 implementation and hot reload start working on that screen !

Also, if I implement Scene1.js as a function (instead of class Scene1 extends Component), then the behavior is the same as with haxe.

@zabojad
Copy link
Author

zabojad commented Feb 13, 2019

To recap:

This renders but does not hot reload:

// Class: screens.Scene1

var $global = typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this

var __map_reserved = {};

// Imports

var $hxClasses = require("./../hxClasses_stub").default;
var $import = require("./../import_stub").default;
var $bind = require("./../bind_stub").default;
var $extend = require("./../extend_stub").default;

const React = require('react');
const { Component } = require('react');
const { View, Text } = require('react-native');

const { Navigation } = require('react-native-navigation');

function Scene1(){
	return (
		<View>
			<Text>Hello 442</Text>
		</View>
	);
}
// Export

module.exports = Scene1;

// exports.default = Scene1;

This renders but does not hot reload:

// Class: screens.Scene1

var $global = typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this

// $global.Object.defineProperty(exports, "__esModule", {value: true});

var __map_reserved = {};

// Imports

var $hxClasses = require("./../hxClasses_stub").default;
var $import = require("./../import_stub").default;
var $bind = require("./../bind_stub").default;
var $extend = require("./../extend_stub").default;
function React_Component() {return require("react");}
// function tools_NavigationUtils() {return require("./../tools/NavigationUtils");}
function React() {return require("react");}
function react__$ReactType_ReactType_$Impl_$() {return require("./../react/_ReactType/ReactType_Impl_");}
// function comps_Row() {return require("./../comps/Row");}
function react_native_component_Text() {return require("react-native");}
function react_native_component_View() {return require("react-native");}


// class Scene1 extends Component {
class Scene1 extends (React_Component().Component) {
	render() {
		var msg = this.props.text != null ? (React()).createElement((react__$ReactType_ReactType_$Impl_$().default).fromComp((react_native_component_Text().Text)),{ },this.props.text) : null;
		return (React()).createElement((react__$ReactType_ReactType_$Impl_$().default).fromComp((react_native_component_View().View)),{ },(React()).createElement((react__$ReactType_ReactType_$Impl_$().default).fromComp((react_native_component_Text().Text)),{ },"This is Scene1 111",msg));
	}
}

// Export

module.exports = Scene1;
// exports.default = Scene1;

This renders AND hot reloads:

// Class: screens.Scene1

var $global = typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this

// $global.Object.defineProperty(exports, "__esModule", {value: true});

var __map_reserved = {};

// Imports

var $hxClasses = require("./../hxClasses_stub").default;
var $import = require("./../import_stub").default;
var $bind = require("./../bind_stub").default;
var $extend = require("./../extend_stub").default;

// Constructor

const React = require('react');
const { Component } = require('react');
const { View, Text } = require('react-native');

class Scene1 extends Component {
	
	render() {
		return (
			<View>
				<Text>Hello 4234567</Text>
			</View>
		);
	}
}

// Export

module.exports = Scene1;
// exports.default = Scene1;

Go and figure :S... Maybe it does not like that in extends (React_Component().Component), React_Component() is a function...

I'll make further tests and try to check the RNN sources if we can find something there...

cc @kiroukou @elsassph @back2dos @kevinresol

@zabojad
Copy link
Author

zabojad commented Feb 13, 2019

I think it is as dumb as that. This also works and hot reload:

// Class: screens.Scene1

var $global = typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this

// $global.Object.defineProperty(exports, "__esModule", {value: true});

var __map_reserved = {};

// Imports

var $hxClasses = require("./../hxClasses_stub").default;
var $import = require("./../import_stub").default;
var $bind = require("./../bind_stub").default;
var $extend = require("./../extend_stub").default;
// function React_Component() {return require("react");}
const { Component } = require("react");
// function tools_NavigationUtils() {return require("./../tools/NavigationUtils");}
function React() {return require("react");}
function react__$ReactType_ReactType_$Impl_$() {return require("./../react/_ReactType/ReactType_Impl_");}
// function comps_Row() {return require("./../comps/Row");}
function react_native_component_Text() {return require("react-native");}
function react_native_component_View() {return require("react-native");}


// class Scene1 extends Component {
class Scene1 extends Component {
	render() {
		var msg = this.props.text != null ? (React()).createElement((react__$ReactType_ReactType_$Impl_$().default).fromComp((react_native_component_Text().Text)),{ },this.props.text) : null;
		return (React()).createElement((react__$ReactType_ReactType_$Impl_$().default).fromComp((react_native_component_View().View)),{ },(React()).createElement((react__$ReactType_ReactType_$Impl_$().default).fromComp((react_native_component_Text().Text)),{ },"This is Scene1 112",msg));
	}
}

// Export

module.exports = Scene1;
// exports.default = Scene1;

@zabojad
Copy link
Author

zabojad commented Feb 13, 2019

This for example, does not hot reload anymore:

const React_Component = require("react");
// class Scene1 extends Component {
class Scene1 extends React_Component.Component {
	render() {
		var msg = this.props.text != null ? (React()).createElement((react__$ReactType_ReactType_$Impl_$().default).fromComp((react_native_component_Text().Text)),{ },this.props.text) : null;
		return (React()).createElement((react__$ReactType_ReactType_$Impl_$().default).fromComp((react_native_component_View().View)),{ },(React()).createElement((react__$ReactType_ReactType_$Impl_$().default).fromComp((react_native_component_Text().Text)),{ },"This is Scene1 1123",msg));
	}
}

It is like it would expect a literal extends Component and nothing else to allow hot reloading to happen...

@zabojad
Copy link
Author

zabojad commented Feb 13, 2019

Tested on iOS, with exactly the same behavior (that's a good point).

@kiroukou
Copy link
Owner

That's an excellent news !
We definitly need to have a closer took to the generation process, see if we can consider to simplify it a bit and avoir the function call here..

@zabojad
Copy link
Author

zabojad commented Feb 13, 2019

@elsassph
Copy link

@kiroukou that's exactly what I told you. A Babel plugin recognises some code patterns to add the hmr wrapper code.

Generating JS code that Babel would recognise is one option, the other is to generate the wrapper code ourselves (see recent hxgenjs issue created by Kevin).

@elsassph
Copy link

Very good find though if there is a difference with RNN. Maybe a different Babel configuration?

@elsassph
Copy link

Here's my reverse engineering of the HMR wrapper code: kevinresol/hxgenjs#27

@francescoagati
Copy link

hi,
but the hot loader of react native reload a class es6 for a file or also with one file with many es6 classes inside? with the new es6 class in haxe 4 we could have better performance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants