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

@:controlled stoped working in Haxe 4.3 #95

Open
AdrianV opened this issue May 3, 2023 · 0 comments
Open

@:controlled stoped working in Haxe 4.3 #95

AdrianV opened this issue May 3, 2023 · 0 comments

Comments

@AdrianV
Copy link

AdrianV commented May 3, 2023

I have this little example that compiles fine under Haxe 4.2.5 or less. With Haxe 4.3.1 it complains with:

"expression should be a field or of type State (found Int)" - for model.value in <ValStepper value={model.value} step={model.step} />

Main.hx

#if !macro
import coconut.data.*;
import coconut.ui.*;
import coconut.Ui.hxx;
import coco.*;
import tink.domspec.*;
import haxe.DynamicAccess;

import js.html.*;
#else
import haxe.macro.Context;
import haxe.macro.Expr;
using tink.MacroApi;
#end
using tink.CoreApi;

import js.Browser.document;
import tink.state.Scheduler;

class ValStepper extends coconut.ui.View {

	@:attribute var step:Int = 1;
	@:controlled var value:Int;
  
	function render() 
	  <div class="counter">
		<button onclick={value -= step}>-</button>
		<span>{value}</span>
		<button onclick={value += step}>+</button>
	  </div>
	;
}
  
class TestModel implements Model {
	@:observable var step: Int = 5;
	@:editable var value: Int = 0;

	@:transition function setStep(v) {
		return {step: v};
	}
}

class TestView1 extends coconut.ui.View {

	@:attribute var model: TestModel;


	function render() {
		return <>
			<div>
				<ValStepper value={model.value} step={model.step} />
			</div>
			<div>{model.value}</div>
		</>;
		
	}
}

class Main {
	static var model = new TestModel();

	static function main() {
		Renderer.mount(document.getElementById('app'), hxx(<TestView1 model={model} />));
		model.setStep(2);
	}
}

build.hxml

-cp src
-D analyzer-optimize
-main Main
--js bin/test.js

--library coconut.vdom
--library coconut.ui
--library coconut.data

--dce full

index.html

<body>
    <div id="app">
        
    </div>
    <script src="test.js" />
</body>
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

1 participant