Skip to content

Commit

Permalink
run prettier rules to pass linting
Browse files Browse the repository at this point in the history
  • Loading branch information
p3t3r67x0 committed Oct 2, 2023
1 parent 93f3970 commit b4290f7
Show file tree
Hide file tree
Showing 11 changed files with 715 additions and 613 deletions.
39 changes: 18 additions & 21 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
import { View, Controller, Component, Router } from '@sndcds/mvc'


export default class App extends Controller {
/* eslint no-useless-constructor: 0 */
constructor(model, view) {
super(model, view)
}
/* eslint no-useless-constructor: 0 */
constructor(model, view) {
super(model, view)
}

initApp(url, id) {
this.data = this.model.getStorage('data')
this.districtId = this.model.getStorage('districtId')
initApp(url, id) {
this.data = this.model.getStorage('data')
this.districtId = this.model.getStorage('districtId')

if (this.districtId === null) {
this.model.setDistrictId(id)
}
else {
this.model.setDistrictId(this.districtId)
}
if (this.districtId === null) {
this.model.setDistrictId(id)
} else {
this.model.setDistrictId(this.districtId)
}

if (this.data === null) {
this.fetchData(url)
}
else {
// this.state.onDataChanged(this.data)
}
if (this.data === null) {
this.fetchData(url)
} else {
// this.state.onDataChanged(this.data)
}
}
}
}
55 changes: 27 additions & 28 deletions src/appModel.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
import { Model } from '@sndcds/mvc'


export default class AppModel extends Model {
constructor() {
super()
this.data = null
this.districtNames = null
this.districtObject = null
this.districtId = null
}
constructor() {
super()
this.data = null
this.districtNames = null
this.districtObject = null
this.districtId = null
}

bindDataChanged(callback) {
this.onDataChanged = callback
}
bindDataChanged(callback) {
this.onDataChanged = callback
}

setDataObject(data) {
this.data = data
this.districtNames = data.map((item) => item.district_name)
this.setStorage('data', data)
}
setDataObject(data) {
this.data = data
this.districtNames = data.map((item) => item.district_name)
this.setStorage('data', data)
}

setDistrictId(districtId) {
this.districtId = districtId
this.setStorage('districtId', districtId)
}
setDistrictId(districtId) {
this.districtId = districtId
this.setStorage('districtId', districtId)
}

setDistrictObject(districtId) {
const condition = (district) => district.district_id === districtId
const items = this.data.filter(condition)
setDistrictObject(districtId) {
const condition = (district) => district.district_id === districtId
const items = this.data.filter(condition)

if (items.length > 0) {
this.districtObject = items[0]
this.setStorage('districtObject', items[0])
}
if (items.length > 0) {
this.districtObject = items[0]
this.setStorage('districtObject', items[0])
}
}
}
}
77 changes: 38 additions & 39 deletions src/districtSelectComponent.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,41 @@
import { Component } from '@sndcds/mvc'


export default class DistrictSelectComponent extends Component {
/* eslint no-useless-constructor: 0 */
constructor(parent, id, setupData) {
super(parent, id, setupData)
}

build() {
this.e = this.domCreateElement('div')
this.parent.e.appendChild(this.e)
}

setProperties(data) {
console.trace()
const selectElement = this.domCreateElement('select')

data.data.forEach((item) => {
const optionElement = this.domCreateElement('option')

optionElement.value = item.district_id
optionElement.textContent = item.district_name

if (optionElement.value === data.districtId) {
optionElement.selected = true
}

selectElement.appendChild(optionElement)
})

this.e.appendChild(selectElement)
}

bindDistrictChanged(handler) {
const e = this.e.children.item(0)
e.addEventListener('change', (event) => {
const selectedOption = e.value
handler(selectedOption - 1)
})
}
}
/* eslint no-useless-constructor: 0 */
constructor(parent, id, setupData) {
super(parent, id, setupData)
}

build() {
this.e = this.domCreateElement('div')
this.parent.e.appendChild(this.e)
}

setProperties(data) {
console.trace()
const selectElement = this.domCreateElement('select')

data.data.forEach((item) => {
const optionElement = this.domCreateElement('option')

optionElement.value = item.district_id
optionElement.textContent = item.district_name

if (optionElement.value === data.districtId) {
optionElement.selected = true
}

selectElement.appendChild(optionElement)
})

this.e.appendChild(selectElement)
}

bindDistrictChanged(handler) {
const e = this.e.children.item(0)
e.addEventListener('change', (event) => {
const selectedOption = e.value
handler(selectedOption - 1)
})
}
}
14 changes: 7 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import PopComponent from './popComponent.js'
import StateController from './stateController.js'

export {
App,
AppModel,
TestComponent,
DistrictSelectComponent,
PopComponent,
StateController
}
App,
AppModel,
TestComponent,
DistrictSelectComponent,
PopComponent,
StateController,
}
29 changes: 20 additions & 9 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import { Model, View, Router, Controller, Component, GridComponent } from '@sndcds/mvc'
import { App, AppModel, TestComponent, DistrictSelectComponent, PopComponent, StateController } from './index.js'

import {
Model,
View,
Router,
Controller,
Component,
GridComponent,
} from '@sndcds/mvc'
import {
App,
AppModel,
TestComponent,
DistrictSelectComponent,
PopComponent,
StateController,
} from './index.js'

// Create an instance of AppModel
const model = new AppModel()
Expand All @@ -12,17 +25,15 @@ const view = new View()
const app = new App(model, view)

// Define routes object with path and name
const routes = [
{ path: '/', controller: 'demoController1' }
]
const routes = [{ path: '/', controller: 'demoController1' }]

const demoController1 = () => {
const a = new StateController(app)
const a = new StateController(app)
}

// Create an object that maps controller names to controller functions.
const controllers = {
demoController1
demoController1,
}

// Create an instance of Router
Expand All @@ -33,4 +44,4 @@ router.start()
app.buildView('root')

// Initialize the application with url and district id
app.initApp('./details.json', 13)
app.initApp('./details.json', 13)
Loading

0 comments on commit b4290f7

Please sign in to comment.