You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/reference.md
+63-8Lines changed: 63 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,18 +7,23 @@ Imba compiles to JavaScript. In the context of APIs you can think of it like Typ
7
7
The global `imba` object contains functions, constants and classes that are included with Imba. Imba also extends the built-in `Element` with certain properties. All items that are imba-specific are marked with a ★ symbol throughout the documentation.
8
8
9
9
### Properties
10
+
10
11
<api-list>imba.own.variables</api-list>
11
12
12
13
### Functions
14
+
13
15
<api-list>imba.own.functions</api-list>
14
16
15
17
### Decorators
18
+
16
19
<api-list>imba.own.decorators</api-list>
17
20
18
21
### Interfaces
22
+
19
23
<api-list>imba.own.interfaces</api-list>
20
24
21
25
## Global interfaces
26
+
22
27
<api-list>own.interfaces</api-list>
23
28
24
29
# /docs/css/properties/display
@@ -28,9 +33,11 @@ The display CSS property sets whether an element is treated as a block or inline
28
33
Formally, the display property sets an element's inner and outer display types. The outer type sets an element's participation in flow layout; the inner type sets the layout of children. Some values of display are fully defined in their own individual specifications; for example the detail of what happens when display: flex is declared is defined in the CSS Flexible Box Model specification.
`locals` is an instance of a JavaScript Proxy object that provides a convenient and efficient way to interact with the global `localStorage`. It wraps around a `Storage` instance, which in turn wraps around the `localStorage` object.
81
+
82
+
### Usage
83
+
84
+
#### Getting a Property
85
+
86
+
You can get a property from `locals` by simply accessing it like `imba.locals.prop`. This will call the getItem method of the Storage class, which retrieves the value from the `localStorage` (if it exists), or from the cache if it's already been retrieved before.
87
+
88
+
```imba
89
+
let value = imba.locals.prop
90
+
```
91
+
92
+
#### Setting a Property
93
+
94
+
You can set a property on `locals` by simply assigning a value to it like `imba.locals.prop = value`. This will call the `setItem` method of the `Storage` class, which stores the value in the `localStorage` and also updates the cache.
95
+
96
+
```imba
97
+
imba.locals.prop = 'value'
98
+
```
99
+
100
+
#### Deleting a Property
101
+
102
+
You can delete a property from `locals` by using the `delete` keyword like `delete locals.prop`. This will call the `deleteProperty` method of the `Storage` class, which removes the value from the `localStorage` and also deletes it from the cache.
103
+
104
+
```imba
105
+
delete imba.locals.prop
106
+
```
107
+
108
+
### Applying a Function
109
+
110
+
You can create a separate namespace or a sub-storage within your `localStorage` by calling it like imba.locals(name). This will call the `apply` method of the `Storage` class, which returns a child Proxy object associated with the given name.
111
+
112
+
Here's an example of how you can use this feature:
113
+
114
+
```imba
115
+
let child = imba.locals('childName')
116
+
child.prop = 'value'
117
+
```
74
118
75
119
# /api/imba/session
76
120
@@ -80,16 +124,16 @@ Documentation coming
80
124
81
125
In addition to the default [built in colors](/docs/css/values/color), `hue0`,`hue1`,`...`,`hue9` refers to the color scale set by the `hue` property. Setting `hue:amber` in css, will make `hue2` refer to `amber2` inside all elements that are affected by this style. The `hue(n)` color values supports an alpha value with the forward-slash syntax like `hue4/40`
82
126
83
-
84
-
85
127
### Syntax
128
+
86
129
```imba
87
130
<div[hue:violet color:hue4]>
88
131
```
89
132
90
133
### Usage
91
134
92
135
Let's say you have a button component with some basic styles:
136
+
93
137
```imba
94
138
# [preview=md]
95
139
import 'util/styles'
@@ -105,6 +149,7 @@ tag Button
105
149
106
150
imba.mount do <Button> "Button"
107
151
```
152
+
108
153
This is all fine, but what if you want to also have a red button, and a green button? Duplicating all the styles involving colors is impractical, especially if you change the design of the button later. With `hue`, we can replace `blue2` with `hue2`, `blue8/70` with `hue8/70` and so on. Then we can set the color scale using the `hue` property.
109
154
110
155
```imba
@@ -117,7 +162,7 @@ tag Button
117
162
text-shadow:0px 1px hue8/70
118
163
bg:hue5 @hover:hue6
119
164
bd:1px solid hue6
120
-
165
+
121
166
<self> <span> <slot>
122
167
123
168
imba.mount do <>
@@ -138,12 +183,15 @@ This is some documentation for the parent!
138
183
# /api/Element/data
139
184
140
185
### Syntax
186
+
141
187
```imba
142
188
<element data=value>
143
189
```
190
+
144
191
## Usage
145
192
146
193
The default convention in imba is to use the data property on elements to pass in the state/data they are supposed to represent. In this example we pass in the movie object through the data property:
194
+
147
195
```imba
148
196
tag movie-item
149
197
# using references to data
@@ -153,8 +201,7 @@ tag movie-item
153
201
<movie-item data=movie>
154
202
```
155
203
156
-
157
-
However, __there is nothing special about the data property__, besides it being declared for all elements. It is just a plain property. If you prefer to use more descriptive properties you are free to do so:
204
+
However, **there is nothing special about the data property**, besides it being declared for all elements. It is just a plain property. If you prefer to use more descriptive properties you are free to do so:
158
205
159
206
```imba
160
207
tag movie-item
@@ -202,16 +249,19 @@ tag movie-item
202
249
### Overriding
203
250
204
251
If you want to do something when setting data, you can easily create a setter and getter:
252
+
205
253
```imba
206
254
tag movie-item
207
255
set data value
208
256
#data = value
209
257
console.log "movie was set",value
210
-
258
+
211
259
get data
212
260
#data
213
261
```
262
+
214
263
The memoized dom works in such a way that the setter will only be triggered when the value actually changes. If you set the property manually outside of rendering, the setter will be called every time, even if the value has not changed:
In this case, the movie-item data setter will only be called when their `data` actually changes, even if we render the list a million times. But if you click a movie-item 10 times, the `movie-card.data` property will be set 10 times. This is only really a challenge if you do something computationally expensive in the `data` setter itself. In that case you can just check if something has changed:
275
+
224
276
```imba
225
277
tag movie-card
226
278
set data value
227
279
if #data != value
228
280
#data = value
229
281
# ... load more info about the movie?
230
-
282
+
231
283
get data
232
284
#data
233
285
```
286
+
234
287
Since Imba embraces the concepts of memoization we have the `=?` operator that is shorthand for the pattern above.
288
+
235
289
```imba
236
290
if item.propname =? value
237
291
# item.propname is now set to value,
@@ -304,6 +358,7 @@ let length = 100px
304
358
let progress = 87%
305
359
let dynamic = (window.innerWidth)px
306
360
```
361
+
307
362
Dimensions are numbers with a unit attached to it. They are compiled and treated as regular strings. When dealing with styles it is nice to be able to write `offset = (point.x)px` instead of `offset = "{point.x}px"`.
308
363
309
364
Time-based units `ms`, `s`, and `fps` are compiled to millisecond-based numbers.
0 commit comments