0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

条件付きルールで動く旅行持ち物リスト生成ツールを作った

0
Posted at

作ったもの

Travel Checklisthttps://sen.ltd/portfolio/travel-checklist/

スクリーンショット

  • 107 アイテムの条件付きデータベース
  • 7 カテゴリ: 書類 / 衣類 / 洗面 / 電子機器 / 健康 / エンタメ / その他
  • トリッププロファイル入力: 行き先・季節・日数・移動手段・目的
  • プロファイル保存(localStorage)
  • カスタムアイテム追加
  • 印刷対応レイアウト

vanilla JS、ゼロ依存、ビルド不要node --test で 37 ケース。

宣言的な条件ルール

{
  id: 'passport',
  conditions: { destination: ['international'] },
},
{
  id: 'laundry-bag',
  conditions: { minDays: 7 },
},
{
  id: 'sunscreen',
  conditions: {
    season: ['summer'],
    tripType: ['beach', 'adventure'],
    conditionLogic: 'any',  // OR
  },
}

3 種類の条件:

  • 配列マッチ: プロファイル値が配列に含まれるか
  • 数値しきい値: minDays / maxDays
  • 論理: conditionLogic: 'any' で AND → OR に切替

ルールは AND がデフォルト

全条件を AND で評価。conditionLogic: 'any' を指定した項目だけ OR に切替。日焼け止めは「夏」「ビーチ旅行」「アドベンチャー旅行」のどれか一つでも該当すれば必要 → OR で表現。

なぜ宣言的か

if (profile.destination === 'international') items.push(passport) のようなハードコードだと、10 アイテムでは動くが 100 アイテムでは破綻する。

宣言的にすることで:

  • 新アイテム追加 = ITEMS に 1 行追加
  • 新条件タイプ追加 = matcher に 1 行追加
  • 複雑度が線形に増える(二乗ではなく)

シリーズ

100+ 公開ポートフォリオ シリーズの #69 です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?