Skip to content
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

Best practice for adding handling items selection #7

Open
npvisual opened this issue May 31, 2019 · 0 comments
Open

Best practice for adding handling items selection #7

npvisual opened this issue May 31, 2019 · 0 comments

Comments

@npvisual
Copy link

Context

I am using MutableObservableArray quite a bit to populate some UITableViews which use the AccessoryType.checkmark to indicate whether a particular cell has been selected or not.

An example of this is MutableObservableArray<RecurrenceByDayOfWeek> which leverages :

// Model defines
public struct RecurrenceByDayOfWeek {
    public let weekday: ShortWeekDays
    public let ordwk: Int
    public let selected: Bool
}

// Service defines
public let byDay: MutableObservableArray<RecurrenceByDayOfWeek> =
    MutableObservableArray(
        ShortWeekDays.allCases.map { 
            RecurrenceByDayOfWeek(weekday: $0,selected: false)
        }
    )

// Binder defines
recurrenceService.byDay.compactMap { $0.collection }
    .observeNext { recurrence in
        recurrence.indices.forEach { index in
            let cell = controller
                .recurrenceTableView
                .cellForRow(at: IndexPath(row: index, section: 1))
            cell?.accessoryType = recurrence[index].selected ? .checkmark : .none
        }
 }.dispose(in: controller.bag)

to indicate whether a day of the week has been selected or not in a table presenting ShortWeekDays (MO, TU, WE, etc.). This helps the end user create a recurrence rule akin to the following examples :

RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE
RRULE:FREQ=WEEKLY;COUNT=10;WKST=SU;BYDAY=TU,TH

Distinction between Model, Service and Binding

While this works fine, the Application logic clearly encroaches on the Business logic / Model. The data itself should only care about which days to include in the BYDAY part of the recurrence rule (if any).

So being "selected" is only a mapping convenience between that state and the resulting string.

Question

So what would be the best way to decouple the Application logic from the Model ? Or is the Model itself (for this case) just a String anyways ?

Should everything we're building to organize the structure of the BYDAY rule part (and by extension, the complete RRULE string) just be some extension of the Application logic (to make it more palatable to structure that data) ?

I am a little confused for this particular scenario.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant