Skip to content

Commit

Permalink
Neaten up compute functions
Browse files Browse the repository at this point in the history
  • Loading branch information
woshibiantai committed Jul 18, 2024
1 parent 7d5f998 commit e8d5de3
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions src/components/ChordChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,29 @@ const props = defineProps({
});
const lines = computed(() => props.chordPro.split('\n'));
const artist = computed(computeArtist);
const bodyLines = computed(computeBodyLines);
const key = computed(computeKey);
const stanzas = computed(computeStanzas);
const tempo = computed(computeTempo);
const time = computed(computeTime);
const title = computed(computeTitle);
const artist = computed(() => {
function computeArtist() {
const artistLine = lines.value.find(line => line.startsWith('{artist:')) || '';
return artistLine.replace('{artist:', '').replace('}', '');
});
const bodyLines = computed(() => lines.value.filter(line => line.trim() !== '' && (!line.startsWith('{') || line.startsWith('{comment:'))));
const key = computed(() => {
}
function computeBodyLines() {
return lines.value.filter(line => line.trim() !== '' && (!line.startsWith('{') || line.startsWith('{comment:')));
}
function computeKey() {
const keyLine = lines.value.find(line => line.startsWith('{key:')) || '';
return keyLine.replace('{key:', '').replace('}', '');
});
const stanzas = computed(() => {
}
function computeStanzas() {
return bodyLines.value.reduce((acc, line) => {
if (line.startsWith('{comment:')) {
acc.push([line]); // Start new stanza
Expand All @@ -76,19 +88,22 @@ const stanzas = computed(() => {
}
return acc;
}, []);
});
const tempo = computed(() => {
}
function computeTempo() {
const tempoLine = lines.value.find(line => line.startsWith('{tempo:')) || '';
return tempoLine.replace('{tempo:', '').replace('}', '');
});
const time = computed(() => {
}
function computeTime() {
const timeLine = lines.value.find(line => line.startsWith('{time:')) || '';
return timeLine.replace('{time:', '').replace('}', '');
});
const title = computed(() => {
}
function computeTitle() {
const titleLine = lines.value.find(line => line.startsWith('{title:')) || '';
return titleLine.replace('{title:', '').replace('}', '');
});
}
</script>

<style scoped>
Expand Down

0 comments on commit e8d5de3

Please sign in to comment.