update
This commit is contained in:
+59
-10
@@ -7,7 +7,7 @@ Bloatless-React is a very minimal and flexible alternative to React.
|
||||
- Supports reactivity through States
|
||||
- Supports JSX for components
|
||||
- Written in TypeScript
|
||||
- Really minimal (under 200 lines)
|
||||
- Really minimal (under 300 lines)
|
||||
- No bloated server or compiler required - just bundle the JavaScript into a static .html file
|
||||
|
||||
# Setup
|
||||
@@ -70,7 +70,7 @@ summary.subscribe(console.log);
|
||||
|
||||
## ListStates
|
||||
|
||||
A ListState\<T\> is a State whose value is a Set\<T\>. A ListState allows specific subscriptions to detect when items get added and removed. This allows dynamic lists to run efficiently.
|
||||
A `ListState<T>` is a State whose value is a `Set<T>`. A ListState allows specific subscriptions to detect when items get added and removed. This allows dynamic lists to run efficiently.
|
||||
|
||||
```TypeScript
|
||||
// Import
|
||||
@@ -78,7 +78,7 @@ import * as React from 'bloatless-react';
|
||||
|
||||
// Define Item type
|
||||
class Item implements React.Identifiable {
|
||||
uuid = new React.UUID();
|
||||
id = React.UUID();
|
||||
constructor(public text: string) {}
|
||||
}
|
||||
|
||||
@@ -99,6 +99,17 @@ listState.add(newItem);
|
||||
listState.remove(newItem);
|
||||
```
|
||||
|
||||
## Persistence
|
||||
|
||||
States can persist through reloads via LocalStorage. To implement this, modify your code like this:
|
||||
```diff
|
||||
-const myState = new React.State("hello");
|
||||
+const myState = React.restoreState("my-state", "hello");
|
||||
|
||||
-const myListState = new React.ListState<Item>();
|
||||
+const myListState = React.restoreListState<Item>("my-list-state");
|
||||
```
|
||||
|
||||
# UI
|
||||
|
||||
For a minimalist stylesheet, I'd recommend checking out my project called [carbon-mini](https://github.com/marlon-erler/carbon-mini/).
|
||||
@@ -107,28 +118,38 @@ Bloatless React provides a modified polyfill for the React API. This means that
|
||||
|
||||
## Handling Events
|
||||
|
||||
The `on:<event>` directive adds an EventListener
|
||||
The `on:<event>` directive adds an EventListener. This directive also supports the `on:enter` event.
|
||||
|
||||
```TypeScript
|
||||
<input on:enter={someFunction}></input>
|
||||
<button on:click={someFunction}>Click me</button>
|
||||
```
|
||||
|
||||
## Changing Properties
|
||||
|
||||
The `subscribe:<property>` directive subscribes to a State and changes the element's property. The property will be changed through the DOM API, so you can use innerText and innerHTML. You can not use this to set attributes.
|
||||
The `subscribe:<property>` directive subscribes to a State and changes a property of the element. Use this for properties available via the DOM model (ie. innerText, innerHTML).
|
||||
|
||||
```TypeScript
|
||||
const name = new React.State("John Doe");
|
||||
<span subscribe:innerText={name}></span>
|
||||
```
|
||||
|
||||
## Setting Attributes
|
||||
|
||||
The `set:<attribute>` directive subscribes to a State and changes an attribute of the element.
|
||||
|
||||
```TypeScript
|
||||
<span set:someAttribute={attributeValue}></span>
|
||||
```
|
||||
|
||||
## Toggling Attributes
|
||||
|
||||
The `toggle:<attribute>` directive toggles attributes on the HTML element without assigning a value. This is useful for the `disabled` attribute.
|
||||
The `toggle:<attribute>` directive toggles attributes on the HTML element without assigning a value. This is useful for the `disabled` attribute. You can use states or normal variables.
|
||||
|
||||
```TypeScript
|
||||
const isDisabled = new React.State(false);
|
||||
<button toggle:disabled={isDisabled}>Some button</button>
|
||||
<button toggle:disabled={false}>Some button</button>
|
||||
```
|
||||
|
||||
## Binding Input Values
|
||||
@@ -151,14 +172,16 @@ import * as React from 'bloatless-react';
|
||||
|
||||
// Define Item
|
||||
class Item implements React.Identifiable {
|
||||
uuid = new React.UUID();
|
||||
id = React.UUID();
|
||||
constructor(public text: string) {}
|
||||
}
|
||||
|
||||
// This ListItemConverter creates an HTML element based on an Item
|
||||
const convertItem: React.ListItemConverter<Item> = (item, listState) => {
|
||||
const convertItem: React.ListItemConverter<Item> = (item) => {
|
||||
function remove() {
|
||||
listState.remove(item);
|
||||
// you should keep track of your data in a separate model
|
||||
// keep your removeListItem() method there
|
||||
myDataModel.removeListItem(item);
|
||||
}
|
||||
return (
|
||||
<span>
|
||||
@@ -204,4 +227,30 @@ document.body.append(
|
||||
- Improve documentation
|
||||
|
||||
## 1.1.3
|
||||
- Add `on:enter` directive
|
||||
- Add `on:enter` directive
|
||||
|
||||
## 1.2.0
|
||||
**BREAKING CHANGES**
|
||||
- Replace UUID class with function;
|
||||
- `new UUID()` => `UUID() returns string`
|
||||
- Replace definition of `Identifiable`
|
||||
- now has `id: string` instead of `uuid: UUID()`
|
||||
|
||||
Other changes:
|
||||
- Add State persistence
|
||||
- Add error description when utilizing `subscribe:children` incorrectly
|
||||
- Fix bug where ListState subscriptions were not called
|
||||
- Improve documentation
|
||||
|
||||
## 1.2.1
|
||||
- Add `set:<attribute>` directive
|
||||
|
||||
## 1.2.2
|
||||
- Remove list parameter from `ListItemConverter`
|
||||
- Add `clear()` method to `ListState`
|
||||
|
||||
## 1.2.3
|
||||
- Allow `toggle:<attribute>` to be used without a state
|
||||
|
||||
## 1.2.4
|
||||
- On `subscribe:children`, scroll new elements into view
|
||||
Reference in New Issue
Block a user