From 1a17437a2fd646e2b76d415bff63cc9f4ff4e730 Mon Sep 17 00:00:00 2001 From: Tomasz Dzieniak Date: Fri, 7 Feb 2020 13:37:12 +0100 Subject: [PATCH 1/4] Update schema to support deferred streams --- .../co/windly/ktxaccount/compiler/scheme.ftl | 96 +++++++++++-------- 1 file changed, 55 insertions(+), 41 deletions(-) diff --git a/ktx-account-compiler/src/main/resources/co/windly/ktxaccount/compiler/scheme.ftl b/ktx-account-compiler/src/main/resources/co/windly/ktxaccount/compiler/scheme.ftl index d0ea5f3..4ace846 100644 --- a/ktx-account-compiler/src/main/resources/co/windly/ktxaccount/compiler/scheme.ftl +++ b/ktx-account-compiler/src/main/resources/co/windly/ktxaccount/compiler/scheme.ftl @@ -44,9 +44,11 @@ abstract class ${schemeClassName}(context: Context) : <#if classEnableReactive> open fun clearRx(<#if schemaMode == "multiple">name: String): Completable = - Completable - .fromAction { clear(<#if schemaMode == "multiple">name) } - .subscribeOn(Schedulers.io()) + Completable.defer { + Completable + .fromAction { clear(<#if schemaMode == "multiple">name) } + } + .subscribeOn(Schedulers.io()) //endregion @@ -84,16 +86,18 @@ abstract class ${schemeClassName}(context: Context) : .andThen(clearSubjects()) private fun clearSubjects(): Completable = - Completable - .fromAction { - <#list descriptorList as descriptor> - - // Tear down "${descriptor.propertyName}" property subject. - if (${descriptor.fieldName}Subject != null) { - ${descriptor.fieldName}Subject = null + Completable.defer { + Completable + .fromAction { + <#list descriptorList as descriptor> + + // Tear down "${descriptor.propertyName}" property subject. + if (${descriptor.fieldName}Subject != null) { + ${descriptor.fieldName}Subject = null + } + } - - } + } //endregion <#list descriptorList as descriptor> @@ -189,9 +193,11 @@ abstract class ${schemeClassName}(context: Context) : */ <#t> open fun saveRx${descriptor.fieldName?cap_first}(<#if schemaMode == "multiple">name: String, ${descriptor.fieldName}: ${descriptor.type.simpleName}): Completable = - Completable - .fromAction { save${descriptor.fieldName?cap_first}(<#if schemaMode == "multiple">name, ${descriptor.fieldName}) } - .subscribeOn(Schedulers.io()) + Completable.defer { + Completable + .fromAction { save${descriptor.fieldName?cap_first}(<#if schemaMode == "multiple">name, ${descriptor.fieldName}) } + } + .subscribeOn(Schedulers.io()) <#if descriptor.enableReactive> @@ -201,32 +207,34 @@ abstract class ${schemeClassName}(context: Context) : */ <#t> open fun getRx${descriptor.fieldName?cap_first}(<#if schemaMode == "multiple">name: String): Single<${descriptor.type.simpleName}> = - Single - .fromPublisher<${descriptor.type.simpleName}> { - - // Retrieve account. - val account = retrieveNullableAccount(<#if schemaMode == "multiple">name) - - // Emit an error for non-existent account. - if (account == null) { - it.onError(NoSuchElementException("Account does not exist.")) - it.onComplete() - return@fromPublisher - } - - // Retrieve property. - val property = manager.getUserData(account, KEY_${descriptor.fieldNameUpperCase}) - - // Complete with default value if property does not exist. - if (property.isNullOrBlank()) { - it.onNext(DEFAULT_${descriptor.fieldNameUpperCase}) + Single.defer<${descriptor.type.simpleName}> { + Single + .fromPublisher<${descriptor.type.simpleName}> { + + // Retrieve account. + val account = retrieveNullableAccount(<#if schemaMode == "multiple">name) + + // Emit an error for non-existent account. + if (account == null) { + it.onError(NoSuchElementException("Account does not exist.")) + it.onComplete() + return@fromPublisher + } + + // Retrieve property. + val property = manager.getUserData(account, KEY_${descriptor.fieldNameUpperCase}) + + // Complete with default value if property does not exist. + if (property.isNullOrBlank()) { + it.onNext(DEFAULT_${descriptor.fieldNameUpperCase}) + it.onComplete() + return@fromPublisher + } + + // Emit property. + it.onNext(property.to${descriptor.type.simpleName}()) it.onComplete() - return@fromPublisher } - - // Emit property. - it.onNext(property.to${descriptor.type.simpleName}()) - it.onComplete() } .subscribeOn(Schedulers.io()) @@ -238,8 +246,11 @@ abstract class ${schemeClassName}(context: Context) : */ <#t> open fun removeRx${descriptor.fieldName?cap_first}(<#if schemaMode == "multiple">name: String): Completable = - Completable - .fromAction { remove${descriptor.fieldName?cap_first}(<#if schemaMode == "multiple">name) } + Completable.defer { + Completable + .fromAction { remove${descriptor.fieldName?cap_first}(<#if schemaMode == "multiple">name) } + } + .subscribeOn(Schedulers.io()) <#if descriptor.enableReactive> @@ -249,11 +260,14 @@ abstract class ${schemeClassName}(context: Context) : */ <#t> open fun observeRx${descriptor.fieldName?cap_first}(<#if schemaMode == "multiple">name: String): Flowable<${descriptor.type.simpleName}> = + Flowable.defer<${descriptor.type.simpleName}> { retrieve${descriptor.fieldName?cap_first}Subject(<#if schemaMode == "multiple">name) .toFlowable(LATEST) <#if descriptor.distinctUntilChanged> .distinctUntilChanged() + } + .subscribeOn(Schedulers.io()) //endregion From 75945a1744a73363a6e88d4d90fe6dd7708e90fd Mon Sep 17 00:00:00 2001 From: Tomasz Dzieniak Date: Fri, 7 Feb 2020 13:38:26 +0100 Subject: [PATCH 2/4] Prepare for release 1.1.3-SNAPSHOT --- CHANGELOG.md | 4 ++++ README.md | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b4b46a..90f71fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Change Log +### Kotlin AndroidX Account 1.1.3 *(2020-02-07)* + + * Migrate schema to support deferred streams. + ### Kotlin AndroidX Account 1.1.2 *(2019-12-04)* * Fix single account scheme to remove only authenticator accounts. diff --git a/README.md b/README.md index d9ae11e..eb48e84 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,8 @@ Add dependencies to the *Kotlin-based* project: ```groovy dependencies { - implementation "co.windly:ktx-account:1.1.2" - kapt "co.windly:ktx-account-compiler:1.1.2" + implementation "co.windly:ktx-account:1.1.3" + kapt "co.windly:ktx-account-compiler:1.1.3" } ``` From c48b465bada2b9b7995e4a40c65d63e739ce6360 Mon Sep 17 00:00:00 2001 From: Tomasz Dzieniak Date: Wed, 26 Feb 2020 18:29:00 +0100 Subject: [PATCH 3/4] Prepare for release 1.1.3 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index deea0fb..2b2b14a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ #region Maven Central -VERSION_NAME=1.1.3-SNAPSHOT +VERSION_NAME=1.1.3 GROUP=co.windly POM_DESCRIPTION=Maintenance POM_URL=https://github.com/tommus/ktx-account From fb96190f77f67d3ae45e67c1250fac89038c586a Mon Sep 17 00:00:00 2001 From: Tomasz Dzieniak Date: Wed, 26 Feb 2020 18:43:03 +0100 Subject: [PATCH 4/4] Prepare next development version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 2b2b14a..d74941d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ #region Maven Central -VERSION_NAME=1.1.3 +VERSION_NAME=1.1.4-SNAPSHOT GROUP=co.windly POM_DESCRIPTION=Maintenance POM_URL=https://github.com/tommus/ktx-account