slicejs-web-framework 1.0.19 → 1.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Slice/Components/Structural/Debugger/Debugger.js +3 -3
- package/Slice/Slice.js +2 -1
- package/package.json +1 -1
- package/src/Components/AppComponents/HomePage/HomePage.css +203 -0
- package/src/Components/AppComponents/HomePage/HomePage.html +49 -0
- package/src/Components/AppComponents/HomePage/HomePage.js +196 -0
- package/src/Components/AppComponents/Playground/Playground.js +0 -15
- package/src/Components/components.js +2 -24
- package/src/routes.js +4 -86
- package/src/sliceConfig.json +0 -3
- package/src/Components/AppComponents/ButtonDocumentation/ButtonDocumentation.css +0 -16
- package/src/Components/AppComponents/ButtonDocumentation/ButtonDocumentation.html +0 -22
- package/src/Components/AppComponents/ButtonDocumentation/ButtonDocumentation.js +0 -102
- package/src/Components/AppComponents/CardDocumentation/CardDocumentation.css +0 -15
- package/src/Components/AppComponents/CardDocumentation/CardDocumentation.html +0 -38
- package/src/Components/AppComponents/CardDocumentation/CardDocumentation.js +0 -113
- package/src/Components/AppComponents/CheckboxDocumentation/CheckboxDocumentation.css +0 -21
- package/src/Components/AppComponents/CheckboxDocumentation/CheckboxDocumentation.html +0 -35
- package/src/Components/AppComponents/CheckboxDocumentation/CheckboxDocumentation.js +0 -103
- package/src/Components/AppComponents/Documentation/Documentation.css +0 -0
- package/src/Components/AppComponents/Documentation/Documentation.html +0 -30
- package/src/Components/AppComponents/Documentation/Documentation.js +0 -75
- package/src/Components/AppComponents/DocumentationPage/DocumentationPage.css +0 -62
- package/src/Components/AppComponents/DocumentationPage/DocumentationPage.html +0 -0
- package/src/Components/AppComponents/DocumentationPage/DocumentationPage.js +0 -283
- package/src/Components/AppComponents/InputDocumentation/InputDocumentation.css +0 -41
- package/src/Components/AppComponents/InputDocumentation/InputDocumentation.html +0 -95
- package/src/Components/AppComponents/InputDocumentation/InputDocumentation.js +0 -315
- package/src/Components/AppComponents/Installation/Installation.css +0 -185
- package/src/Components/AppComponents/Installation/Installation.html +0 -102
- package/src/Components/AppComponents/Installation/Installation.js +0 -61
- package/src/Components/AppComponents/LandingMenu/LandingMenu.css +0 -108
- package/src/Components/AppComponents/LandingMenu/LandingMenu.html +0 -16
- package/src/Components/AppComponents/LandingMenu/LandingMenu.js +0 -33
- package/src/Components/AppComponents/LandingPage/LandingPage.css +0 -14
- package/src/Components/AppComponents/LandingPage/LandingPage.html +0 -0
- package/src/Components/AppComponents/LandingPage/LandingPage.js +0 -53
- package/src/Components/AppComponents/MainMenu/MainMenu.css +0 -80
- package/src/Components/AppComponents/MainMenu/MainMenu.html +0 -39
- package/src/Components/AppComponents/MainMenu/MainMenu.js +0 -42
- package/src/Components/AppComponents/MyLayout/MyLayout.css +0 -0
- package/src/Components/AppComponents/MyLayout/MyLayout.html +0 -0
- package/src/Components/AppComponents/MyLayout/MyLayout.js +0 -13
- package/src/Components/AppComponents/MyNavigation/MyNavigation.css +0 -49
- package/src/Components/AppComponents/MyNavigation/MyNavigation.html +0 -1
- package/src/Components/AppComponents/MyNavigation/MyNavigation.js +0 -60
- package/src/Components/AppComponents/RoutingDocumentation/RoutingDocumentation.css +0 -89
- package/src/Components/AppComponents/RoutingDocumentation/RoutingDocumentation.html +0 -108
- package/src/Components/AppComponents/RoutingDocumentation/RoutingDocumentation.js +0 -177
- package/src/Components/AppComponents/ServiceDocumentation/ServiceDocumentation.css +0 -82
- package/src/Components/AppComponents/ServiceDocumentation/ServiceDocumentation.html +0 -74
- package/src/Components/AppComponents/ServiceDocumentation/ServiceDocumentation.js +0 -416
- package/src/Components/AppComponents/SliceStylesDocumentation/SliceStylesDocumentation.css +0 -56
- package/src/Components/AppComponents/SliceStylesDocumentation/SliceStylesDocumentation.html +0 -28
- package/src/Components/AppComponents/SliceStylesDocumentation/SliceStylesDocumentation.js +0 -134
- package/src/Components/AppComponents/SliceTeamCard/SliceTeamCard.css +0 -104
- package/src/Components/AppComponents/SliceTeamCard/SliceTeamCard.html +0 -12
- package/src/Components/AppComponents/SliceTeamCard/SliceTeamCard.js +0 -74
- package/src/Components/AppComponents/StructuralDocumentation/StructuralDocumentation.css +0 -72
- package/src/Components/AppComponents/StructuralDocumentation/StructuralDocumentation.html +0 -98
- package/src/Components/AppComponents/StructuralDocumentation/StructuralDocumentation.js +0 -219
- package/src/Components/AppComponents/SwitchDocumentation/SwitchDocumentation.css +0 -21
- package/src/Components/AppComponents/SwitchDocumentation/SwitchDocumentation.html +0 -35
- package/src/Components/AppComponents/SwitchDocumentation/SwitchDocumentation.js +0 -103
- package/src/Components/AppComponents/TheBuildMethod/TheBuildMethod.css +0 -296
- package/src/Components/AppComponents/TheBuildMethod/TheBuildMethod.html +0 -89
- package/src/Components/AppComponents/TheBuildMethod/TheBuildMethod.js +0 -86
- package/src/Components/AppComponents/TheSliceTeam/TheSliceTeam.css +0 -208
- package/src/Components/AppComponents/TheSliceTeam/TheSliceTeam.html +0 -18
- package/src/Components/AppComponents/TheSliceTeam/TheSliceTeam.js +0 -111
- package/src/Components/AppComponents/ThemesDocumentation/ThemesDocumentation.css +0 -61
- package/src/Components/AppComponents/ThemesDocumentation/ThemesDocumentation.html +0 -80
- package/src/Components/AppComponents/ThemesDocumentation/ThemesDocumentation.js +0 -149
- package/src/Components/AppComponents/VisualDocumentation/VisualDocumentation.css +0 -70
- package/src/Components/AppComponents/VisualDocumentation/VisualDocumentation.html +0 -67
- package/src/Components/AppComponents/VisualDocumentation/VisualDocumentation.js +0 -193
- package/src/Components/AppComponents/WhatIsSlice/WhatIsSlice.css +0 -475
- package/src/Components/AppComponents/WhatIsSlice/WhatIsSlice.html +0 -389
- package/src/Components/AppComponents/WhatIsSlice/WhatIsSlice.js +0 -95
- /package/src/Components/{AppComponents → Visual}/CodeVisualizer/CodeVisualizer.css +0 -0
- /package/src/Components/{AppComponents → Visual}/CodeVisualizer/CodeVisualizer.html +0 -0
- /package/src/Components/{AppComponents → Visual}/CodeVisualizer/CodeVisualizer.js +0 -0
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
<h1 id="routing">Routing in Slice.js</h1>
|
|
2
|
-
<p>
|
|
3
|
-
Slice.js provides a powerful and flexible routing system that allows you to create single-page applications
|
|
4
|
-
with multiple views. The routing system is built on top of the browser's History API and offers both
|
|
5
|
-
declarative and programmatic ways to define and navigate between routes.
|
|
6
|
-
</p>
|
|
7
|
-
|
|
8
|
-
<h2 id="router-setup">Router Setup</h2>
|
|
9
|
-
<p>
|
|
10
|
-
Slice.js routing starts with defining your routes in a configuration file. By default, Slice.js looks for
|
|
11
|
-
this configuration in <code>src/routes.js</code>, but you can customize the path in <code>sliceConfig.json</code>.
|
|
12
|
-
</p>
|
|
13
|
-
|
|
14
|
-
<div class="routes-config-example"></div>
|
|
15
|
-
|
|
16
|
-
<p>
|
|
17
|
-
The route configuration consists of an array of route objects, each with at least a <code>path</code> and a
|
|
18
|
-
<code>component</code> property. The router uses this configuration to match URL paths to components.
|
|
19
|
-
</p>
|
|
20
|
-
|
|
21
|
-
<div class="routing-visualization"></div>
|
|
22
|
-
|
|
23
|
-
<h2 id="route-component">Using the Route Component</h2>
|
|
24
|
-
<p>
|
|
25
|
-
The <code>slice-route</code> component is the simplest way to define a route in your components. It renders the specified
|
|
26
|
-
component when the current URL matches the defined path.
|
|
27
|
-
</p>
|
|
28
|
-
|
|
29
|
-
<div class="route-component-example"></div>
|
|
30
|
-
|
|
31
|
-
<p>
|
|
32
|
-
When defining a route component, you need to specify:
|
|
33
|
-
</p>
|
|
34
|
-
<ul>
|
|
35
|
-
<li><strong>path</strong>: The URL path that triggers this route</li>
|
|
36
|
-
<li><strong>component</strong>: The name of the component to render when the path matches</li>
|
|
37
|
-
</ul>
|
|
38
|
-
|
|
39
|
-
<h2 id="multi-route-component">Using the MultiRoute Component</h2>
|
|
40
|
-
<p>
|
|
41
|
-
The <code>slice-multi-route</code> component allows you to define multiple routes in a single component. This
|
|
42
|
-
is particularly useful for sections of your application that have multiple related views, like dashboards or
|
|
43
|
-
content management systems.
|
|
44
|
-
</p>
|
|
45
|
-
|
|
46
|
-
<div class="multi-route-example"></div>
|
|
47
|
-
|
|
48
|
-
<p>
|
|
49
|
-
The MultiRoute component takes an array of route objects through its <code>routes</code> property. Each route
|
|
50
|
-
object has the same structure as in the main routes configuration.
|
|
51
|
-
</p>
|
|
52
|
-
|
|
53
|
-
<h2 id="dynamic-routes">Dynamic Routes with Parameters</h2>
|
|
54
|
-
<p>
|
|
55
|
-
Slice.js supports dynamic routes with URL parameters. You can define parameters in your route paths using the
|
|
56
|
-
<code>${paramName}</code> syntax. These parameters are then passed to your component through the <code>props.params</code> object.
|
|
57
|
-
</p>
|
|
58
|
-
|
|
59
|
-
<div class="dynamic-routes-example"></div>
|
|
60
|
-
|
|
61
|
-
<p>
|
|
62
|
-
When a dynamic route matches, the parameters are extracted from the URL and made available to your component.
|
|
63
|
-
This allows you to create reusable components that can display different content based on the URL parameters.
|
|
64
|
-
</p>
|
|
65
|
-
|
|
66
|
-
<h2 id="programmatic-navigation">Programmatic Navigation</h2>
|
|
67
|
-
<p>
|
|
68
|
-
In addition to declarative routing with components, Slice.js provides a programmatic way to navigate between
|
|
69
|
-
routes using the <code>slice.router.navigate()</code> method.
|
|
70
|
-
</p>
|
|
71
|
-
|
|
72
|
-
<div class="programmatic-nav-example"></div>
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
<h2 id="nested-routes">Nested Routes and Layouts</h2>
|
|
77
|
-
<p>
|
|
78
|
-
Slice.js supports nested routes, which are powerful for creating complex UIs with shared layouts. You can
|
|
79
|
-
define child routes in the route configuration, and they will inherit the parent route's path as a prefix.
|
|
80
|
-
</p>
|
|
81
|
-
|
|
82
|
-
<div class="nested-routes-example"></div>
|
|
83
|
-
|
|
84
|
-
<p>
|
|
85
|
-
In this example, the AdminLayout component acts as a container for all administrative pages, providing a
|
|
86
|
-
consistent layout while the content area changes based on the current route.
|
|
87
|
-
</p>
|
|
88
|
-
|
|
89
|
-
<h2 id="route-lifecycle">Route Lifecycle and Events</h2>
|
|
90
|
-
<p>
|
|
91
|
-
When a route changes, Slice.js router triggers several events:
|
|
92
|
-
</p>
|
|
93
|
-
<ol>
|
|
94
|
-
<li>The previous component is removed from the DOM</li>
|
|
95
|
-
<li>The new component is built and inserted into the DOM</li>
|
|
96
|
-
<li>If the new component has an <code>init</code> method, it's called</li>
|
|
97
|
-
<li>If switching between routes that use the same component, the <code>update</code> method is called instead</li>
|
|
98
|
-
</ol>
|
|
99
|
-
|
|
100
|
-
<h2 id="route-best-practices">Best Practices for Routing</h2>
|
|
101
|
-
<ul>
|
|
102
|
-
<li>Organize your routes logically, grouping related routes together with nested routes</li>
|
|
103
|
-
<li>Use the most specific component for your routing needs - Route for single routes, MultiRoute for related groups</li>
|
|
104
|
-
<li>Keep route parameters simple and descriptive</li>
|
|
105
|
-
<li>Add a catch-all 404 route to handle unmatched paths</li>
|
|
106
|
-
<li>Consider adding loading indicators during navigation, especially for routes that fetch data</li>
|
|
107
|
-
<li>Use the programmatic navigation API for complex navigation scenarios like redirects or conditional navigation</li>
|
|
108
|
-
</ul>
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
export default class RoutingDocumentation extends HTMLElement {
|
|
2
|
-
constructor(props) {
|
|
3
|
-
super();
|
|
4
|
-
slice.attachTemplate(this);
|
|
5
|
-
|
|
6
|
-
slice.controller.setComponentProps(this, props);
|
|
7
|
-
this.debuggerProps = [];
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
async init() {
|
|
11
|
-
// Code examples for the documentation
|
|
12
|
-
const routesConfigExample = await slice.build("CodeVisualizer", {
|
|
13
|
-
language: "javascript",
|
|
14
|
-
value: `// src/routes.js
|
|
15
|
-
const routes = [
|
|
16
|
-
{ path: "/", component: "HomePage" },
|
|
17
|
-
{ path: "/about", component: "AboutPage" },
|
|
18
|
-
{ path: "/contact", component: "ContactPage" },
|
|
19
|
-
{
|
|
20
|
-
path: "/blog",
|
|
21
|
-
component: "BlogPage",
|
|
22
|
-
children: [
|
|
23
|
-
{ path: "/post/:id", component: "BlogPostPage" },
|
|
24
|
-
{ path: "/category/:category", component: "BlogCategoryPage" }
|
|
25
|
-
]
|
|
26
|
-
},
|
|
27
|
-
{ path: "/dashboard", component: "DashboardPage" },
|
|
28
|
-
{ path: "/404", component: "NotFoundPage" }
|
|
29
|
-
];
|
|
30
|
-
|
|
31
|
-
export default routes;`
|
|
32
|
-
});
|
|
33
|
-
this.querySelector(".routes-config-example").appendChild(routesConfigExample);
|
|
34
|
-
|
|
35
|
-
const routeComponentExample = await slice.build("CodeVisualizer", {
|
|
36
|
-
language: "javascript",
|
|
37
|
-
value: `
|
|
38
|
-
// Creating a Route component programmatically
|
|
39
|
-
const userProfileRoute = await slice.build("Route", {
|
|
40
|
-
path: "/profile",
|
|
41
|
-
component: "UserProfile"
|
|
42
|
-
});
|
|
43
|
-
document.querySelector(".content-container").appendChild(userProfileRoute);
|
|
44
|
-
});`
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
this.querySelector(".route-component-example").appendChild(routeComponentExample);
|
|
48
|
-
|
|
49
|
-
const multiRouteExample = await slice.build("CodeVisualizer", {
|
|
50
|
-
language: "javascript",
|
|
51
|
-
value: `// Creating a MultiRoute component in JavaScript
|
|
52
|
-
const dashboardRoutes = await slice.build("MultiRoute", {
|
|
53
|
-
routes: [
|
|
54
|
-
{ path: "/dashboard", component: "DashboardHome" },
|
|
55
|
-
{ path: "/dashboard/profile", component: "UserProfile" },
|
|
56
|
-
{ path: "/dashboard/settings", component: "UserSettings" },
|
|
57
|
-
{ path: "/dashboard/activity", component: "UserActivity" }
|
|
58
|
-
]
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
// Add it to your layout
|
|
62
|
-
document.querySelector(".dashboard-content").appendChild(dashboardRoutes);`
|
|
63
|
-
});
|
|
64
|
-
this.querySelector(".multi-route-example").appendChild(multiRouteExample);
|
|
65
|
-
|
|
66
|
-
const dynamicRoutesExample = await slice.build("CodeVisualizer", {
|
|
67
|
-
language: "javascript",
|
|
68
|
-
value: `// Route with parameters in routes.js
|
|
69
|
-
{ path: "/user/\${id}", component: "UserProfile" }
|
|
70
|
-
|
|
71
|
-
// Accessing parameters in the component
|
|
72
|
-
export default class UserProfile extends HTMLElement {
|
|
73
|
-
constructor(props) {
|
|
74
|
-
super();
|
|
75
|
-
slice.attachTemplate(this);
|
|
76
|
-
|
|
77
|
-
// Access the parameter from props
|
|
78
|
-
const userId = props.params.id;
|
|
79
|
-
console.log(\`Loading profile for user \${userId}\`);
|
|
80
|
-
|
|
81
|
-
// Rest of component implementation...
|
|
82
|
-
}
|
|
83
|
-
}`
|
|
84
|
-
});
|
|
85
|
-
this.querySelector(".dynamic-routes-example").appendChild(dynamicRoutesExample);
|
|
86
|
-
|
|
87
|
-
const programmaticNavExample = await slice.build("CodeVisualizer", {
|
|
88
|
-
language: "javascript",
|
|
89
|
-
value: `// Navigate programmatically
|
|
90
|
-
const navigateButton = await slice.build("Button", {
|
|
91
|
-
value: "Go to Dashboard",
|
|
92
|
-
onClickCallback: async () => {
|
|
93
|
-
// Navigate to a new route
|
|
94
|
-
await slice.router.navigate("/dashboard");
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
// Create a link component
|
|
99
|
-
const profileLink = await slice.build("Link", {
|
|
100
|
-
text: "View Profile",
|
|
101
|
-
path: "/dashboard/profile",
|
|
102
|
-
classes: "nav-link"
|
|
103
|
-
});`
|
|
104
|
-
});
|
|
105
|
-
this.querySelector(".programmatic-nav-example").appendChild(programmaticNavExample);
|
|
106
|
-
|
|
107
|
-
const nestedRoutesExample = await slice.build("CodeVisualizer", {
|
|
108
|
-
language: "javascript",
|
|
109
|
-
value: `// Nested routes configuration
|
|
110
|
-
const routes = [
|
|
111
|
-
{
|
|
112
|
-
path: "/admin",
|
|
113
|
-
component: "AdminLayout", // This will be the parent layout
|
|
114
|
-
children: [
|
|
115
|
-
{ path: "/dashboard", component: "AdminDashboard" },
|
|
116
|
-
{ path: "/users", component: "UserManagement" },
|
|
117
|
-
{ path: "/settings", component: "AdminSettings" }
|
|
118
|
-
]
|
|
119
|
-
}
|
|
120
|
-
];
|
|
121
|
-
|
|
122
|
-
// In AdminLayout component
|
|
123
|
-
export default class AdminLayout extends HTMLElement {
|
|
124
|
-
constructor(props) {
|
|
125
|
-
super();
|
|
126
|
-
slice.attachTemplate(this);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
async init() {
|
|
130
|
-
// The layout remains the same, while child routes render in this container
|
|
131
|
-
const contentArea = this.querySelector(".admin-content");
|
|
132
|
-
|
|
133
|
-
// Create a MultiRoute for the child routes
|
|
134
|
-
const childRoutes = await slice.build("MultiRoute", {
|
|
135
|
-
routes: [
|
|
136
|
-
{ path: "/admin/dashboard", component: "AdminDashboard" },
|
|
137
|
-
{ path: "/admin/users", component: "UserManagement" },
|
|
138
|
-
{ path: "/admin/settings", component: "AdminSettings" }
|
|
139
|
-
]
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
contentArea.appendChild(childRoutes);
|
|
143
|
-
}
|
|
144
|
-
}`
|
|
145
|
-
});
|
|
146
|
-
this.querySelector(".nested-routes-example").appendChild(nestedRoutesExample);
|
|
147
|
-
|
|
148
|
-
// Create navigation visualization examples
|
|
149
|
-
const navVisualization = document.createElement("div");
|
|
150
|
-
navVisualization.classList.add("route-visualization");
|
|
151
|
-
|
|
152
|
-
const routeDiv = document.createElement("div");
|
|
153
|
-
routeDiv.classList.add("visualization-route");
|
|
154
|
-
routeDiv.innerHTML = `
|
|
155
|
-
<div class="vis-route-path">/about</div>
|
|
156
|
-
<div class="vis-route-component">AboutPage Component</div>
|
|
157
|
-
`;
|
|
158
|
-
|
|
159
|
-
const multiRouteDiv = document.createElement("div");
|
|
160
|
-
multiRouteDiv.classList.add("visualization-multiroute");
|
|
161
|
-
multiRouteDiv.innerHTML = `
|
|
162
|
-
<div class="vis-route-container">
|
|
163
|
-
<div class="vis-route-path">/dashboard</div>
|
|
164
|
-
<div class="vis-route-path">/dashboard/profile</div>
|
|
165
|
-
<div class="vis-route-path">/dashboard/settings</div>
|
|
166
|
-
</div>
|
|
167
|
-
<div class="vis-route-component">Currently Active Component</div>
|
|
168
|
-
`;
|
|
169
|
-
|
|
170
|
-
navVisualization.appendChild(routeDiv);
|
|
171
|
-
navVisualization.appendChild(multiRouteDiv);
|
|
172
|
-
|
|
173
|
-
this.querySelector(".routing-visualization").appendChild(navVisualization);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
customElements.define("slice-routingdocumentation", RoutingDocumentation);
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
slice-servicedocumentation {
|
|
2
|
-
color: var(--font-primary-color);
|
|
3
|
-
font-family: var(--font-family);
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
slice-servicedocumentation h1,
|
|
7
|
-
slice-servicedocumentation h2,
|
|
8
|
-
slice-servicedocumentation h3 {
|
|
9
|
-
margin-top: 1.5em;
|
|
10
|
-
margin-bottom: 0.5em;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
slice-servicedocumentation p {
|
|
14
|
-
line-height: 1.6;
|
|
15
|
-
margin: 1em 0;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
slice-servicedocumentation ul,
|
|
19
|
-
slice-servicedocumentation ol {
|
|
20
|
-
margin: 1em 0;
|
|
21
|
-
padding-left: 2em;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
slice-servicedocumentation li {
|
|
25
|
-
margin-bottom: 0.5em;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
slice-servicedocumentation code {
|
|
29
|
-
font-family: monospace;
|
|
30
|
-
background-color: var(--secondary-background-color);
|
|
31
|
-
padding: 0.2em 0.4em;
|
|
32
|
-
border-radius: 3px;
|
|
33
|
-
font-size: 0.9em;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
slice-servicedocumentation .service-example,
|
|
37
|
-
slice-servicedocumentation .service-usage-example,
|
|
38
|
-
slice-servicedocumentation .fetch-manager-example,
|
|
39
|
-
slice-servicedocumentation .local-storage-example,
|
|
40
|
-
slice-servicedocumentation .indexed-db-example,
|
|
41
|
-
slice-servicedocumentation .translator-example,
|
|
42
|
-
slice-servicedocumentation .custom-service-example {
|
|
43
|
-
margin: 1.5em 0;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
slice-servicedocumentation strong {
|
|
47
|
-
color: var(--primary-color);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
slice-servicedocumentation .faq-section {
|
|
51
|
-
margin: 2em 0;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
slice-servicedocumentation .faq-section slice-details {
|
|
55
|
-
margin-bottom: 1em;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
slice-servicedocumentation table {
|
|
59
|
-
width: 100%;
|
|
60
|
-
border-collapse: collapse;
|
|
61
|
-
margin: 1.5em 0;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
slice-servicedocumentation th,
|
|
65
|
-
slice-servicedocumentation td {
|
|
66
|
-
padding: 0.75em;
|
|
67
|
-
text-align: left;
|
|
68
|
-
border-bottom: 1px solid var(--primary-color-shade);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
slice-servicedocumentation th {
|
|
72
|
-
background-color: var(--primary-color);
|
|
73
|
-
color: var(--primary-color-contrast);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
slice-servicedocumentation .service-section {
|
|
77
|
-
padding: 1em;
|
|
78
|
-
margin: 1em 0;
|
|
79
|
-
border-left: 3px solid var(--primary-color);
|
|
80
|
-
background-color: var(--secondary-background-color);
|
|
81
|
-
border-radius: 0 var(--border-radius-slice) var(--border-radius-slice) 0;
|
|
82
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
<h1 id="serviceComponents">Service Components</h1>
|
|
2
|
-
|
|
3
|
-
<p>
|
|
4
|
-
Service components in Slice.js handle business logic and data operations without a visual representation. They provide reusable functionality that can be shared across visual components, serving as the backbone of your application's data layer and business logic.
|
|
5
|
-
</p>
|
|
6
|
-
|
|
7
|
-
<h2 id="serviceComponentOverview">What are Service Components?</h2>
|
|
8
|
-
<p>
|
|
9
|
-
Service components in Slice.js:
|
|
10
|
-
</p>
|
|
11
|
-
<ul>
|
|
12
|
-
<li>Handle data operations, API communication, and business logic</li>
|
|
13
|
-
<li>Don't have visual representation or DOM elements</li>
|
|
14
|
-
<li>Can be shared across multiple visual components</li>
|
|
15
|
-
<li>Often follow the singleton pattern (one instance shared throughout the application)</li>
|
|
16
|
-
<li>Provide a clean separation between UI and business logic</li>
|
|
17
|
-
</ul>
|
|
18
|
-
|
|
19
|
-
<h2 id="buildingServiceComponents">Creating Service Components</h2>
|
|
20
|
-
<p>
|
|
21
|
-
Here's a basic example of a service component that fetches and caches data from an API:
|
|
22
|
-
</p>
|
|
23
|
-
<div class="service-example"></div>
|
|
24
|
-
|
|
25
|
-
<h2 id="usingServiceComponents">Using Service Components</h2>
|
|
26
|
-
<p>
|
|
27
|
-
Services are built using <code>slice.build()</code> just like visual components, but they interact differently with the application:
|
|
28
|
-
</p>
|
|
29
|
-
<div class="service-usage-example"></div>
|
|
30
|
-
|
|
31
|
-
<h2 id="builtInServices">Built-in Service Components</h2>
|
|
32
|
-
|
|
33
|
-
<h3 id="fetchManager">FetchManager</h3>
|
|
34
|
-
<p>
|
|
35
|
-
The FetchManager service simplifies API communication with features like automatic loading indicators, timeout handling, error management, and response caching:
|
|
36
|
-
</p>
|
|
37
|
-
<div class="fetch-manager-example"></div>
|
|
38
|
-
|
|
39
|
-
<h3 id="localStorageManager">LocalStorageManager</h3>
|
|
40
|
-
<p>
|
|
41
|
-
The LocalStorageManager service provides a simplified interface for working with browser localStorage, including automatic JSON serialization and error handling:
|
|
42
|
-
</p>
|
|
43
|
-
<div class="local-storage-example"></div>
|
|
44
|
-
|
|
45
|
-
<h3 id="indexedDbManager">IndexedDbManager</h3>
|
|
46
|
-
<p>
|
|
47
|
-
The IndexedDbManager service offers a simplified API for working with IndexedDB, providing methods for CRUD operations on object stores:
|
|
48
|
-
</p>
|
|
49
|
-
<div class="indexed-db-example"></div>
|
|
50
|
-
|
|
51
|
-
<h3 id="translator">Translator</h3>
|
|
52
|
-
<p>
|
|
53
|
-
The Translator service enables internationalization in your application, allowing you to support multiple languages:
|
|
54
|
-
</p>
|
|
55
|
-
<div class="translator-example"></div>
|
|
56
|
-
|
|
57
|
-
<h2 id="customServices">Creating Custom Service Components</h2>
|
|
58
|
-
<p>
|
|
59
|
-
You can create custom service components for specific application needs. Here's an example of a custom authentication service:
|
|
60
|
-
</p>
|
|
61
|
-
<div class="custom-service-example"></div>
|
|
62
|
-
|
|
63
|
-
<h2 id="serviceComponentBestPractices">Best Practices</h2>
|
|
64
|
-
<ul>
|
|
65
|
-
<li><strong>Single Responsibility</strong>: Each service should focus on a specific domain or functionality</li>
|
|
66
|
-
<li><strong>Error Handling</strong>: Implement robust error handling and logging within services</li>
|
|
67
|
-
<li><strong>Caching Strategy</strong>: Use appropriate caching strategies to improve performance</li>
|
|
68
|
-
<li><strong>Service Composition</strong>: Compose complex services by combining simpler services</li>
|
|
69
|
-
<li><strong>Dependency Injection</strong>: Pass dependencies to services through their constructors</li>
|
|
70
|
-
<li><strong>Consistent API</strong>: Design service APIs with consistent naming and behavior patterns</li>
|
|
71
|
-
</ul>
|
|
72
|
-
|
|
73
|
-
<h2 id="serviceComponentsFaq">Frequently Asked Questions</h2>
|
|
74
|
-
<div class="faq-section"></div>
|