mirror of
https://github.com/esiur/esiur-dart.git
synced 2025-05-05 19:52:58 +00:00
Sync/Async setters
This commit is contained in:
parent
0dba5f277a
commit
8959f52f6e
@ -24,16 +24,12 @@ void main(List<String> arguments) async {
|
||||
..addOption('username', abbr: 'u')
|
||||
..addOption('password', abbr: 'p')
|
||||
..addOption('dir', abbr: 'd')
|
||||
..addFlag('sync', abbr: 's', defaultsTo: false)
|
||||
..addFlag(
|
||||
"getx",
|
||||
abbr: 'x',
|
||||
defaultsTo: false,
|
||||
help: "Generate apropriate getx bindings for resources",
|
||||
)
|
||||
..addFlag(
|
||||
"namedargs",
|
||||
help:
|
||||
"Use named arguments instead of positional arguments for resource methods",
|
||||
help: "Generate apropriate getx bindings for resources.",
|
||||
);
|
||||
|
||||
var results = parser.parse(arguments.skip(2));
|
||||
@ -45,14 +41,12 @@ void main(List<String> arguments) async {
|
||||
//print("Username ${username} password ${password} dir ${dir}");
|
||||
|
||||
// make template
|
||||
var destDir = await TemplateGenerator.getTemplate(
|
||||
link,
|
||||
dir: dir,
|
||||
username: username,
|
||||
password: password,
|
||||
getx: results['getx'],
|
||||
namedArgs: results["namedargs"],
|
||||
);
|
||||
var destDir = await TemplateGenerator.getTemplate(link,
|
||||
dir: dir,
|
||||
username: username,
|
||||
password: password,
|
||||
getx: results['getx'],
|
||||
asyncSetters: !results['sync']);
|
||||
|
||||
print("Generated directory `${destDir}`");
|
||||
|
||||
@ -72,12 +66,13 @@ void printUsage() {
|
||||
print("");
|
||||
print("Available commands:");
|
||||
print("\tget-template\tGet a template from an IIP link.");
|
||||
print("\tversion: print esiur version.");
|
||||
print("\tversion: Print Esiur version.");
|
||||
print("");
|
||||
print("Global options:");
|
||||
print("\t-u, --username\tAuthentication username");
|
||||
print("\t-p, --password\tAuthentication password");
|
||||
print("\t-d, --dir\tName of the directory to generate model inside.");
|
||||
print("\t-s, --async\tSynchronous property setters.");
|
||||
}
|
||||
|
||||
void printVersion() async {
|
||||
|
@ -443,13 +443,17 @@ class DistributedConnection extends NetworkConnection with IStore {
|
||||
|
||||
if (dataType.identifier ==
|
||||
TransmissionTypeIdentifier.ResourceList) {
|
||||
// remove from suspended.
|
||||
_suspendedResources.remove(r.distributedResourceInstanceId);
|
||||
|
||||
// parse them as int
|
||||
var id = data.getUint32(8);
|
||||
|
||||
// id changed ?
|
||||
if (id != r.distributedResourceInstanceId)
|
||||
r.distributedResourceInstanceId = id;
|
||||
|
||||
_neededResources[id] = r;
|
||||
_suspendedResources.remove(id);
|
||||
|
||||
await fetch(id, null);
|
||||
}
|
||||
|
@ -266,14 +266,12 @@ class TemplateGenerator {
|
||||
return v == null || v == "";
|
||||
}
|
||||
|
||||
static Future<String> getTemplate(
|
||||
String url, {
|
||||
String? dir,
|
||||
String? username,
|
||||
String? password,
|
||||
bool getx = false,
|
||||
bool namedArgs = false,
|
||||
}) async {
|
||||
static Future<String> getTemplate(String url,
|
||||
{String? dir,
|
||||
String? username,
|
||||
String? password,
|
||||
bool getx = false,
|
||||
bool asyncSetters = true}) async {
|
||||
try {
|
||||
if (!_urlRegex.hasMatch(url)) throw Exception("Invalid IIP URL");
|
||||
|
||||
@ -328,7 +326,8 @@ class TemplateGenerator {
|
||||
var source = "";
|
||||
if (tmp.type == TemplateType.Resource) {
|
||||
source = makeImports(tmp) +
|
||||
generateClass(tmp, templates, getx: getx, namedArgs: namedArgs);
|
||||
generateClass(tmp, templates,
|
||||
getx: getx, asyncSetters: asyncSetters);
|
||||
} else if (tmp.type == TemplateType.Record) {
|
||||
source = makeImports(tmp) + generateRecord(tmp, templates);
|
||||
} else if (tmp.type == TemplateType.Enum) {
|
||||
@ -418,7 +417,7 @@ class TemplateGenerator {
|
||||
TypeTemplate template,
|
||||
List<TypeTemplate> templates, {
|
||||
bool getx = false,
|
||||
bool namedArgs = false,
|
||||
bool asyncSetters = true,
|
||||
}) {
|
||||
var className = template.className.split('.').last;
|
||||
|
||||
@ -520,8 +519,13 @@ class TemplateGenerator {
|
||||
template.properties.where((p) => !p.inherited).forEach((p) {
|
||||
var ptTypeName = getTypeName(template, p.valueType, templates);
|
||||
rt.writeln("${ptTypeName} get ${p.name} { return get(${p.index}); }");
|
||||
rt.writeln(
|
||||
"set ${p.name}(${ptTypeName} value) { setSync(${p.index}, value); }");
|
||||
|
||||
if (asyncSetters)
|
||||
rt.writeln(
|
||||
"set ${p.name}(${ptTypeName} value) { set(${p.index}, value); }");
|
||||
else
|
||||
rt.writeln(
|
||||
"set ${p.name}(${ptTypeName} value) { setSync(${p.index}, value); }");
|
||||
});
|
||||
|
||||
template.events.where((e) => !e.inherited).forEach((e) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user