
Product
Socket Now Supports pylock.toml Files
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
@readr-media/react-election-votes-comparison
Advanced tools
## How to Use This Pkg? ### Data Loaders `DataLoader` class 可以撈取多種不同選舉的結果,和執行一次性資料撈取或是週期性資料撈取。 目前支援的選舉類型(`type`)包括: - `councilMember`:縣市議員 - `mayor`: 縣市長 - `legislator`: 立法委員 - `president`: 總統 - `referendum`: 公投
DataLoader
class 可以撈取多種不同選舉的結果,和執行一次性資料撈取或是週期性資料撈取。
目前支援的選舉類型(type
)包括:
councilMember
:縣市議員mayor
: 縣市長legislator
: 立法委員president
: 總統referendum
: 公投年份(year
)的部分,根據不同的選舉類型,有不同的選舉年份。
目前支援的年份包括:
然而,因為每種選舉的資料維度不盡相同,
所以在使用 DataLoader
時,需要提供「區域」(districts
)。
「縣市議員」和「立法委員」可以提供的區域包含:
taipeiCity
newTaipeiCity
taoyuanCity
taichungCity
tainanCity
kaohsiungCity
hsinchuCounty
miaoliCounty
changhuaCounty
nantouCounty
yunlinCounty
chiayiCounty
pingtungCounty
yilanCounty
hualienCounty
taitungCounty
penghuCounty
kinmenCounty
lienchiangCounty
keelungCity
hsinchuCity
chiayiCity
「立法委員(不分區)」的區域為 party
。
「立法委員(原住民)」的區域為 indigenous
。
「總統」、「公投」和「縣市長」的區域為 all
。
範例:
import evc from '@readr-media/react-election-votes-comparison'
const DataLoader = evc.DataLoader
let ldr
// 抓取「2018 年台北市議員」選舉結果
ldr = new DataLoader({
type: 'councilMember',
year: '2018',
districts: 'taipeiCity',
})
const data = await ldr.loadData()
// 抓取「2020 年總統」選舉結果
ldr = new DataLoader({
type: 'president',
year: '2020',
districts: 'all',
})
const data = await ldr.loadData()
// 抓取「2020 年不分區立法委員」選舉結果
ldr = new DataLoader({
type: 'legislator',
year: '2020',
districts: 'party',
})
const data = await ldr.loadData()
// 抓取「2022 年公投」選舉結果
ldr = new DataLoader({
type: 'referendum',
year: '2022',
districts: 'all',
})
const data = await ldr.loadData()
DataLoader
除了 loadData
method 可以使用,亦可以使用 loadDataPeriodically
method。
該 method 會解析 response header 中的 Cache-Control
,將 max-age
的值抓出來,當作下一次 request 的 timer。
如果 max-age
不存在,則 timer 會設定為一個小時。
註:
目前沒有處理 no-store
,如果有需要,需要再補邏輯。
範例:
// anotherComponent.jsx
import EVC from '@readr-media/react-election-votes-comparison'
const DataLoader = EVC.DataLoader
const EVCComponent = EVC.ReactComponent.EVC
function AnotherComponent(props) {
const [data, setData] = useState({})
useEffect(() => {
let dataLoader = new DataLoader({
year: '2018', // 年份
type: 'councilMember', // 選舉類型
area: 'taipeiCity', // 縣市
})
const handleError = (errMsg, errObj) => {
// do something for loading error
}
const handleData = (data) => {
// call React component `setState`
setState(data)
}
dataLoader.addEventListener('error', handleError)
dataLoader.addEventListener('data', setState)
// after register event listener
// start to load data periodically
dataLoader.loadDataPeriodically()
return () => {
dataLoader.removeEventListener('error', handleError)
dataLoader.removeEventListener('data', setState)
dataLoader = null
}
}, [])
return (
<EVCComponent
election={data}
device="rwd" // value could be 'rwd' or 'mobile'
/>
)
}
EVC
component 的 UI 是參考下面 mockups 實作:
使用上僅需將 DataLoader
抓取回來的資料丟入 EVC
的 election
prop 即可。
由於選舉模板的票數比較的 mockup,需要 EVC
可以強制 render mobile 版本,
所以在 EVC
props 上,提供了 device
prop 給使用者。
當 device="mobile"
時,EVC
會強制呈現 mobile 版本;當 device="rwd"
(預設)時,
EVC
會根據 media query 來決定要 render 哪個版本。
Sample codes:
import evc from '@readr-media/react-election-votes-comparison'
const DataLoader = evc.DataLoader
const EVCComponent = evc.ReactComponent.EVC
async function load() {
const dataLoader = new DataLoader({
year: '2018', // 年份
type: 'councilMember', // 選舉類型
area: 'taipeiCity', // 縣市
})
let data
try {
// fetch data once
data = await dataLoader.loadData()
} catch(err) {
// handle error
}
return data
}
function renderComponent(data) {
return (
<EVCComponent
election={data}
device="rwd" // value could be 'rwd' or 'mobile'
/>
)
}
yarn install
$ yarn dev
// or
$ npm run dev
// or
$ make dev
$ npm run build
// or
$ make build
After executing Build
scripts, we will have ./dist
and /lib
folders,
and then we can execute publish command,
npm publish
Note: before publish npm package, we need to bump the package version first.
FAQs
## How to Use This Pkg? ### Data Loaders `DataLoader` class 可以撈取多種不同選舉的結果,和執行一次性資料撈取或是週期性資料撈取。 目前支援的選舉類型(`type`)包括: - `councilMember`:縣市議員 - `mayor`: 縣市長 - `legislator`: 立法委員 - `president`: 總統 - `referendum`: 公投
The npm package @readr-media/react-election-votes-comparison receives a total of 42 weekly downloads. As such, @readr-media/react-election-votes-comparison popularity was classified as not popular.
We found that @readr-media/react-election-votes-comparison demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 9 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
Security News
Research
Socket uncovered two npm packages that register hidden HTTP endpoints to delete all files on command.
Research
Security News
Malicious Ruby gems typosquat Fastlane plugins to steal Telegram bot tokens, messages, and files, exploiting demand after Vietnam’s Telegram ban.