Tôi muốn biết những ưu và nhược điểm của việc sử dụng Cấu trúc Fractal trong dự án React + Redux và tôi đã tự hỏi là có ai có kinh nghiệm với phương pháp này không hoặc nếu có những cạm bẫy không thể nhìn thấy ngay từ tài liệu.Cấu trúc dự án Fractal với React và Redux - ưu/nhược điểm
(cấu trúc Fractal) Còn được gọi là: Tự Đựng Apps, Recursive Route Hierarchy, nhà cung cấp, vv
Bối cảnh: Tôi nhìn vào react-redux-starter-kit và nó cho thấy sử dụng một fractal structure để sắp xếp các thư mục. Nếu tôi hiểu rõ, phương pháp này yêu cầu tổ chức các thư mục dự án theo tính năng và lồng đường định tuyến.
Vì vậy, nếu tôi có một "sự kiện" tài nguyên nơi
/events
liệt kê tất cả các sự kiện/events/new
hiển thị một hình thức để chèn một sự kiện mới/events/1/details
hiển thị các thông tin chi tiết về sự kiện với id 1
Bắt đầu từ bản mẫu, tôi phải thêm thư mục tuyến mới như:
├── src # Application source code
│ ├── main.js # Application bootstrap and rendering
│ ├── components # Reusable Presentational Components
│ ├── containers # Reusable Container Components
│ ├── layouts # Components that dictate major page structure
│ ├── static # Static assets (not imported anywhere in source code)
│ ├── styles # Application-wide styles (generally settings)
│ ├── store # Redux-specific pieces
│ └── routes # Main route definitions and async split points
│ ├── index.js # Bootstrap main application routes with store
│ ├── Root.js # Wrapper component for context-aware providers
~ ~
│ ├── Events # Fractal route
│ │ ├── index.js # Route definitions and async split points
│ │ ├── components # Presentational React Components
│ │ ├── container # Connect components to actions and store
│ │ ├── modules # Collections of reducers/constants/actions or single DUCK module
│ │ └── routes # Fractal sub-routes (** optional) <-------------
│ │ │
│ │ └── New
│ │ │ ├── index.js # Route definitions and async split points
│ │ │ ├── assets # Assets required to render components
│ │ │ ├── components # Presentational React Components
│ │ │ ├── container # Connect components to actions and store
│ │ │ ├── modules # Collections of reducers/constants/actions or single DUCK module
│ │ │ └── routes # Fractal sub-routes (** optional) <-------------
│ │ │
│ │ └── Details
│ │ ├── index.js # Route definitions and async split points
│ │ ├── assets # Assets required to render components
│ │ ├── components # Presentational React Components
│ │ ├── container # Connect components to actions and store
│ │ ├── modules # Collections of reducers/constants/actions or single DUCK module
│ │ └── routes # Fractal sub-routes (** optional) <-------------
~ ~
│ └── NotFound # Capture unknown routes in component
~
Với New
và Details
thư mục lồng nhau dưới gốc Event
thư mục.
Các tài liệu nổi bật này ưu chính:
- Nó quy mô tốt hơn so với một cấu trúc thư mục bằng phẳng, với các thư mục cho linh kiện, container vv
- Tuyến đường có thể được đóng gói thành "khối" sử dụng thuật toán tách và hợp nhất của webpack
- Vì logic là khép kín, các tuyến đường có thể dễ dàng được chia thành các kho riêng biệt và được tham chiếu với plugin DLL của webpack để linh hoạt, phát triển hiệu suất cao d khả năng mở rộng.
hey @NickGnd trải nghiệm của bạn với bộ phản ứng-redux-starter-kit như thế nào? –
Một kẻ giết người không tìm thấy trong 1½ năm. Đây có thể là cấu trúc cho dự án tiếp theo của tôi. – np8