-
-
Save barneycarroll/b30aa36825b52e11c3feb9c44fd12692 to your computer and use it in GitHub Desktop.
Using modules not components for associated functionalities, with state management left to application space
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {ordinals, defaultRange, rangeFromOrdinal, Calendar} from './DateRange.js' | |
const state = { | |
...rangeFromOrdinal('Today'), | |
showCalendar : false, | |
} | |
m.mount(document.body, { | |
view: () => [ | |
m('form', | |
m('h1', 'When are you going on holiday?'), | |
m('select', { | |
onchange(e){ | |
const ordinal = e.target.selectedOptions[0] | |
Object.assign(state, rangeFromOrdinal(ordinal)) | |
}, | |
...(state.showCalendar && {disabled : true}), | |
}, | |
ordinals.map(ordinal => m('option', ordinal)), | |
), | |
m('label', | |
m('input[type=checkbox]', { | |
checked: state.showCalendar, | |
onchange(e){ | |
showCalendar = e.target.checked | |
}, | |
}), | |
), | |
state.showCalendar && | |
m(Calendar, { | |
selectedRange: [state.startDate, state.endDate], | |
onchange({startDate, endDate}){ | |
Object.assign(state, {startDate, endDate}) | |
}, | |
}), | |
), | |
] | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import moment from 'moment' | |
export const ordinals = Object.freeze(['Today', 'Yesterday', 'Last 7 days']) | |
export const defaultRange = Object.freeze({startDate: x, endDate: y}) | |
export function rangeFromOrdinal(ordinal){ | |
return {startDate: x, endDate: y} | |
} | |
export function Calendar(){ | |
return { | |
view: () => | |
m('h1', '(A calendar UI)') | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment