@base-framework/atoms 1.0.22 → 1.0.23

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.
Files changed (2) hide show
  1. package/README.md +68 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -124,6 +124,74 @@ Section([
124
124
  ])
125
125
  ```
126
126
 
127
+ ## Special Atoms
128
+ Special atoms are atoms that have been pre-configured with specific properties. These atoms are designed to simplify the creation of common components. This library has a few special atoms that can help create complex actions.
129
+
130
+ ### On Atom
131
+ The On atom allows a child to be added or removed based on a bindable data property. This atom makes the child not need to have am "onSet" property on a parent wrapper allowing for easier layouts with less code.
132
+
133
+ ```javascript
134
+
135
+ // The traditional way using a parent wrapper with an onSet property
136
+ Div({
137
+ class: "p-4 transition",
138
+ onState: ["loaded", (loaded) => (!loaded)
139
+ ? SkeletonPost()
140
+ : Post(post)
141
+ ]
142
+ })
143
+
144
+ // The new way using the On atom
145
+ Div({ class: "p-4 transition" }, [
146
+ On('loaded', (loaded) => (!loaded)
147
+ ? SkeletonPost()
148
+ : Post(post))
149
+ ])
150
+
151
+ // Or with a state
152
+ Div({ class: "p-4 transition" }, [
153
+ OnState('loaded', (loaded) => (!loaded)
154
+ ? SkeletonPost()
155
+ : Post(post))
156
+ ])
157
+
158
+ // Children can now be added dynamically without a wrapper
159
+ Div({ class: "p-4 transition" }, [
160
+ H1('Title'),
161
+
162
+ // this will add or remove this child based on the loaded state
163
+ On('loaded', (loaded) => (!loaded)
164
+ ? SkeletonPost()
165
+ : Post(post))
166
+ ])
167
+
168
+ ```
169
+
170
+ The On and OnState atoms support two overloads. The first overload is the data property to bind to and the second is the callback function that will be called when the data property changes.
171
+
172
+ ### On Atom Overloads
173
+ ```javascript
174
+
175
+ // This will watch to the component data, or context data, or component state in that order if the first two are not set in the component.
176
+ // data property, callback
177
+ On('loaded', (loaded) => (!loaded)
178
+ ? SkeletonPost()
179
+ : Post(post))
180
+
181
+ ```
182
+
183
+ The second overload allows for a custom data source to be use. This alllows for more flexibility with the layouts.
184
+
185
+ ```javascript
186
+
187
+ // watching on the component route
188
+ // data source, data property, callback
189
+ On(this.route, 'loaded', (loaded) => (!loaded)
190
+ ? SkeletonPost()
191
+ : Post(post))
192
+
193
+ ```
194
+
127
195
  ## Contributing
128
196
 
129
197
  Contributions to Base Framework are welcome. Follow these steps to contribute:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base-framework/atoms",
3
- "version": "1.0.22",
3
+ "version": "1.0.23",
4
4
  "description": "This will add default atoms to the base framework.",
5
5
  "main": "./dist/atoms.js",
6
6
  "scripts": {