Skip to content

Commit 9ad6814

Browse files
committed
Reworked the resource initialisation and loading functions so that modules
can be requested simultaneously.
1 parent a39959c commit 9ad6814

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

lib/src/resources.dart

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,21 @@ abstract class Resources
1414
this._modules.add(module);
1515
}
1616

17-
// Future<List<Language>> Languages();
17+
1818
Future Initialise({ void onError(String) }) async
1919
{
20+
List<Future<TranslatableModule>> loading = [];
21+
2022
// Retrieve values for current language and check if any expected values
2123
// are missing or unexpected values found
2224
for (var m in this._modules)
2325
{
24-
await LoadModule(m, null);
26+
loading.add(LoadModule(m, null));
27+
}
28+
29+
for (var l in loading)
30+
{
31+
var m = await l;
2532

2633
if ((m.missing || m.orphaned) && onError != null)
2734
{
@@ -65,13 +72,19 @@ abstract class Resources
6572
Future<List<TranslatableModule>> Load(String language) async
6673
{
6774
List<TranslatableModule> result = [];
75+
List<Future<TranslatableModule>> loading = [];
6876

6977
for (var m in this._modules)
7078
{
71-
var module = await this.LoadModule(
79+
loading.add(this.LoadModule(
7280
TranslatableModule.base(m.name, Map.from(m.values)),
7381
language
74-
);
82+
));
83+
}
84+
85+
for (var l in loading)
86+
{
87+
var module = await l;
7588

7689
module.originals = Map.from(module.values);
7790
result.add(module);
@@ -80,5 +93,4 @@ abstract class Resources
8093
return result;
8194
}
8295

83-
8496
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: translatable
2-
version: 1.1.0
2+
version: 1.1.1
33
author: Dan Parnham <dan@emergent-design.co.uk>
44
homepage: https://github.com/emergent-design/translatable
55
description: >-

0 commit comments

Comments
 (0)