I used dart-sass to learn and implement a Dart library used in Node.js. Everything works fine (thanks Dart Sass team!). However I would also like to call static methods in Dart classes from JavaScript.
I created JsClass.defineStaticMethods()
to add them to a class in Dart but I cannot add them to self.exports.ClassName.methodName
automatically. Example:
var jsClass = createJSClass('ClassName', (Object self, String value) {
return ClassName(value);
});
jsClass.defineStaticMethods({
'fromJson': (Object jsJson) => ClassName.fromJson(objectToMap(jsJson)),
});
I did manage to add them manually. For example:
set$ClassName(obj, v) {
obj.ClassName = v;
obj.ClassName.fromJson = function (jsJson) {
return A.ClassName_fromJson(A.objectToMap(type$.Object._as(jsJson)));
};
return obj.ClassName;
}
Has anybody managed to use Dart’s js interop to add static methods to classes?
It would be great if dart-sass needed to call static methods in Dart classes - they would know how to implement it :-)