가져온 패키지 라이브러리에 모델 클래스가 정의 된 경우 폴리머 요소 에서 모델을 사용하는 올바른 방법은 무엇입니까?모델 클래스?
나는 정확하다고 생각합니다 (예 : How to subscribe to change of an observable field 등).
DARTIUM에서 작동하지만 JS에 빌드 된 경우에는 작동하지 않습니다. 나는 그곳에서 무슨 일이 일어나고 있는지 실제로 파악할 수 없다. 필드의 리스너와 값이 이상하게 작동합니다.
주요 요인 : 내 모델 클래스는 몇 가지 이유에 대한 공유 라이브러리에 포장 내가 놓친 게 무엇 내 입력 요소
를 사용해야합니까? 아니면 dart2js에 버그가 있습니까?
FILES 및 로그
testlib.dart (단지 패키지 라이브러리에서 모델이 아닌 폴리머 응용 프로그램의 일부) :
library testlib;
import 'package:observe/observe.dart';
class MyModel extends Object with Observable{
@observable String foo;
String toString(){
return "MyModel[foo:$foo]";
}
}
그리고 우리가 가지고있는 고분자 응용 프로그램에서 :
all_elements.dart (mode all_elements.html
<polymer-element name="my-input">
<template>
<p>My Input</p>
<input type="text" value="{{value}}"/>
</template>
</polymer-element>
<polymer-element name="my-form">
<template>
<my-input value="{{model.foo}}"></my-input>
</template>
</polymer-element>
<script type="application/dart" src="all_elements.dart"></script>
및 응용 프로그램의 엔트리 포인트 ...)
library test;
import 'package:polymer/polymer.dart';
import 'package:testlib/testlib.dart'; //!!!! note this is important, I need shared model
@CustomTag('my-input')
class MyInput extends PolymerElement {
@published String value;
valueChanged(oldValue){
print('text changed from "$oldValue" to "$value"');
}
MyInput.created() : super.created();
}
@CustomTag('my-form')
class MyForm extends PolymerElement {
@observable MyModel model = new MyModel();
modelChanged(oldValue){
print('text changed from "$oldValue" to "$model"');
}
MyForm.created() : super.created();
void ready(){
model.changes.listen((changes){
print('model properties changed $changes');
});
}
}
및 : testapp.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test app</title>
<link rel="import" href="all_elements.html">
<script type="application/dart">export 'package:polymer/init.dart';</script>
<script src="packages/browser/dart.js"></script>
</head>
<body>
<my-form></my-form>
</body>
</html>
LOGS리터 패키지를 사용하여 가져 :
JS가 빌드 될 때까지 모든 것이 잘 작동합니다. 입력 단어 "안녕하세요"를 작성하려고 할 때 내가 얻을 :
DARTIUM을 - OK
text changed from "null" to "h"
model properties changed [#<PropertyChangeRecord Symbol("foo") from: null to: h>]
text changed from "h" to "he"
model properties changed [#<PropertyChangeRecord Symbol("foo") from: h to: he>]
text changed from "he" to "hel"
model properties changed [#<PropertyChangeRecord Symbol("foo") from: he to: hel>]
text changed from "hel" to "hell"
model properties changed [#<PropertyChangeRecord Symbol("foo") from: hel to: hell>]
text changed from "hell" to "hello"
model properties changed [#<PropertyChangeRecord Symbol("foo") from: hell to: hello>]
자바 스크립트 - 문제 (유형 "안녕하세요"- 수, "신비"유형 "그러는"- GET "mytr")
text changed from "null" to "h"
model properties changed [#<PropertyChangeRecord Symbol("foo") from: null to: h>]
text changed from "h" to "he"
text changed from "he" to "h"
model properties changed [#<PropertyChangeRecord Symbol("foo") from: h to: he>]
text changed from "h" to "hl"
text changed from "hl" to "he"
model properties changed [#<PropertyChangeRecord Symbol("foo") from: he to: hl>]
text changed from "he" to "hel"
text changed from "hel" to "hl"
model properties changed [#<PropertyChangeRecord Symbol("foo") from: hl to: hel>]
text changed from "hl" to "hlo"
text changed from "hlo" to "hel"
감사합니다 . 모델은 재사용 가능한 구성 요소 및 기능의 일부입니다. 나는 그것을 새로운 애플 리케이션에 복사하고 싶지 않지만 그것을 링크하고 싶다. 그리고 잠시 디버깅을하고 있지만, 성공하지 못하면 (지금은 ;-)) 누군가가이 문제를 해결하는지 묻습니다. 그 이유와 받아 들일 수있는 해결책을 발견했을 때, 나는 알게 될 것이다 ... – Rob