This repository was archived by the owner on Jun 20, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +23
-9
lines changed Expand file tree Collapse file tree 2 files changed +23
-9
lines changed Original file line number Diff line number Diff line change @@ -200,13 +200,7 @@ class AnalyticsImpl implements Analytics {
200200 }
201201
202202 @override
203- String get clientId => properties['clientId' ];
204-
205- void _initClientId () {
206- if (clientId == null ) {
207- properties['clientId' ] = new Uuid ().generateV4 ();
208- }
209- }
203+ String get clientId => properties['clientId' ] ?? = new Uuid ().generateV4 ();
210204
211205 /**
212206 * Send raw data to analytics. Callers should generally use one of the typed
@@ -227,8 +221,6 @@ class AnalyticsImpl implements Analytics {
227221 if (! enabled) return new Future .value ();
228222
229223 if (_bucket.removeDrop ()) {
230- _initClientId ();
231-
232224 _variableMap.forEach ((key, value) {
233225 args[key] = value;
234226 });
Original file line number Diff line number Diff line change @@ -62,6 +62,28 @@ void defineTests() {
6262 mock.sendScreenView ('baz' );
6363 return mock.waitForLastPing (timeout: new Duration (milliseconds: 100 ));
6464 });
65+
66+ group ('clientId' , () {
67+ test ('is available immediately' , () {
68+ AnalyticsImplMock mock = createMock ();
69+ expect (mock.clientId, isNotEmpty);
70+ });
71+
72+ test ('is memoized' , () {
73+ AnalyticsImplMock mock = createMock ();
74+ final value1 = mock.clientId;
75+ final value2 = mock.clientId;
76+ expect (value1, isNotEmpty);
77+ expect (value1, value2);
78+ });
79+
80+ test ('is stored in properties' , () {
81+ AnalyticsImplMock mock = createMock ();
82+ expect (mock.properties['clientId' ], isNull);
83+ final value = mock.clientId;
84+ expect (mock.properties['clientId' ], value);
85+ });
86+ });
6587 });
6688
6789 group ('postEncode' , () {
You can’t perform that action at this time.
0 commit comments