8000 Improve Form DSL by dbaelz · Pull Request #22 · TheJuki/KFormMaster · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Improve Form DSL #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 17, 2018
Merged

Improve Form DSL #22

merged 2 commits into from
May 17, 2018

Conversation

dbaelz
Copy link
Contributor
@dbaelz dbaelz commented May 17, 2018

Goals

This pull request improves the DSL to create a well-formed structure. It prevents the construction of invalid and undesirable nesting within the elements. This also makes the resulting DSL easier to understand.

Implementation Details

The DslMarker annotation enforces some useful rules for DSLs. See this article for more information. An example of a currently possible, but poorly structured DSL (see comments):

formBuilder = form(this, recyclerView, this, true) {
            header { title = getString(R.string.PersonalInfo) }
            email(Email.ordinal) {
                title = getString(R.string.email)
                hint = getString(R.string.email_hint)

                // The element is nested within itself
                email {
                    title = getString(R.string.app_name)
                    hint = getString(R.string.email_hint)
                }
            }
            password(Password.ordinal) {
                title = getString(R.string.password)

                // Another element is nested in a undesirable way
                header {
                    title = getString(R.string.app_name)
                }
            }
            phone(Phone.ordinal) {
                title = getString(R.string.Phone)
                value = "+8801712345678"

                // Insane deep nesting
                text(Location.ordinal) {
                    title = getString(R.string.Location)
                    value = "Dhaka"
                    text(Location.ordinal) {
                        title = getString(R.string.Location)
                        value = "Dhaka"
                        text(Location.ordinal) {
                            title = getString(R.string.Location)
                            value = "Dhaka"
                            text(Location.ordinal) {
                                title = getString(R.string.Location)
                                value = "Dhaka"
                            }
                        }
                    }
                }
            }
        }

Such a nesting now raises an error.

Testing Details

The DSL examples in the app are well-formed and work as intended. Therefore, no adjustments in the tests are required.

@TheJuki
Copy link
Owner
TheJuki commented May 17, 2018

This is helpful. Thanks! I'll wait until Travis CI builds it and then I will merge this.

@codecov
Copy link
codecov bot commented May 17, 2018

Codecov Report

Merging #22 into master will increase coverage by 0.05%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             master    #22      +/-   ##
==========================================
+ Coverage     51.94%    52%   +0.05%     
  Complexity      176    176              
==========================================
  Files            55     55              
  Lines          1748   1748              
  Branches        371    371              
==========================================
+ Hits            908    909       +1     
+ Misses          555    554       -1     
  Partials        285    285
Impacted Files Coverage Δ Complexity Δ
...java/com/thejuki/kformmaster/helper/FormBuilder.kt 86.78% <ø> (ø) 0 <0> (ø) ⬇️
.../com/thejuki/kformmaster/helper/FormBuildHelper.kt 29.31% <ø> (ø) 11 <0> (ø) ⬇️
...i/kformmaster/view/FormPickerDateTimeViewBinder.kt 55.81% <0%> (+2.32%) 3% <0%> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3470cfe...526d1dc. Read the comment docs.

@TheJuki TheJuki merged commit fdbbe46 into TheJuki:master May 17, 2018
@dbaelz dbaelz deleted the dbaelz/improve-form-dsl branch May 17, 2018 20:59
@TheJuki TheJuki added the bug Something isn't working label May 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0