Skip to content

Commit

Permalink
version 0.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
YarikTH committed Feb 12, 2023
1 parent 8cc90c3 commit f3a2f82
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 15 deletions.
70 changes: 70 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,76 @@
All notable changes to this project will be documented in this file. This
project adheres to [Semantic Versioning](http://semver.org/).

## [0.9.0](https://github.com/YarikTH/ureact/releases/tag/0.9.0) (2023-02-12)

[Full Changelog](https://github.com/YarikTH/ureact/compare/0.8.1...0.9.0)

Great closure/adaptor rework

- BREAKING! `sink` and `fork` introduced in 0.8.0 are removed because they don't
fit into the library and lead to a lot of complicated logic to support them
- BREAKING! ureact::closure is renamed and moved in ureact::detail namespace
library is not ready for such extension point yet
- BREAKING! free functions that create new reactives (signals/events/observes)
from existing ones also called "algorithms" are replaced with inline constexpr
instances of special functor-like classes inherited from Adaptor or AdaptorClosure.
This is the same approach as used in std::ranges and range-v3.
There are some differences in usage compared with free functions:
- [Argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl)
is not working with adaptors, so namespace is required, while before it was optional
```C++
ureact::context ctx;
ureact::var_signal<int> src = make_var( ctx, 1 );

// before 0.9.0
ureact::signal<int> minus_src = lift( src, std::negate<>{} );

// after 0.9.0
ureact::signal<int> minus_src = ureact::lift( src, std::negate<>{} );
```
- single argument adaptors like ureact::monitor and ureact::count no longer
require functional call scopes
```C++
ureact::context ctx;
ureact::var_signal src = make_var( ctx, 1 );

// before 0.9.0
ureact::signal changes = src | ureact::monitor() | ureact::count();

// after 0.9.0
ureact::signal changes = src | ureact::monitor | ureact::count;
```
- unlike free functions, adaptors can't have optional template arguments, so
new adaptors with underscopes are introduced for such cases, because <>
would be required for default case.
```C++
ureact::context ctx;
ureact::event_source<int> src = make_source<int>( ctx );
// before 0.9.0
ureact::signal<size_t> changes = src | ureact::count();
ureact::signal<float> changes_f = src | ureact::count<float>();
// after 0.9.0
ureact::signal<size_t> changes = src | ureact::count;
ureact::signal<float> changes_f = src | ureact::count_<float>;
```
- BREAKING! yet another great headers rework:
- `ureact/take_drop.hpp` is separated into
`ureact/take.hpp` and `ureact/drop.hpp`
- `ureact/take_drop_while.hpp` is separated into
`ureact/take_while.hpp` and `ureact/drop_while.hpp`
- all adaptors are moved into `ureact/adaptor` subdirectory.
As a result library headers become easier to navigate.
- New adaptor `ureact::once` is introduced.
Or reintroduced, because it was added before and then removed in 0.6.0.
It is merely a `ureact::take(1)` overload with more precise name.
- `ureact::signal_pack` is reworked to hold tuple of signals
instead of tuple of signal references.
It reduces space for errors and reduces artificial complexity
when working with signal_pack with a tiny cost of copying shared
pointers on reactive value construction.
## [0.8.1](https://github.com/YarikTH/ureact/releases/tag/0.8.1) (2023-01-29)
[Full Changelog](https://github.com/YarikTH/ureact/compare/0.8.0...0.8.1)
Expand Down
20 changes: 9 additions & 11 deletions doc/signals_vs_callbacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,9 @@ What it boils down to, is that the change propagation must be handled by hand.
The next example shows how signals can be used for this scenario.


## Final solution: Signals ([run](https://godbolt.org/z/qe3PnK8x7))
## Final solution: Signals ([run](https://godbolt.org/z/KcfrzKvMM))

```cpp
#include "ureact/ureact.hpp"

class Shape
{
public:
Expand All @@ -216,8 +214,8 @@ ureact::context ctx;
Shape myShape( ctx );

// Set dimensions
myShape.width.set( 20 );
myShape.height.set( 20 );
myShape.width( 20 );
myShape.height( 20 );

// Get size
const auto curSize = myShape.size();
Expand All @@ -226,14 +224,14 @@ const auto curSize = myShape.size();
Every reactive value automatically supports registration of callbacks (they are called observers):
```cpp
// Callback on change
observe( myShape.size,
[]( int newSize ) { std::cout << "size -> " << newSize << "\n"; } );
ureact::observe( myShape.size,
[]( int newSize ) { std::cout << "size -> " << newSize << "\n"; } );
// Those would work, too
observe( myShape.width,
[]( int newWidth ) { std::cout << "width -> " << newWidth << "\n"; } );
observe( myShape.height,
[]( int newHeight ) { std::cout << "height -> " << newHeight << "\n"; } );
ureact::observe( myShape.width,
[]( int newWidth ) { std::cout << "width -> " << newWidth << "\n"; } );
ureact::observe( myShape.height,
[]( int newHeight ) { std::cout << "height -> " << newHeight << "\n"; } );
```

---------------
Expand Down
2 changes: 1 addition & 1 deletion include/ureact/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#define UREACT_VERSION_MAJOR 0
#define UREACT_VERSION_MINOR 9
#define UREACT_VERSION_PATCH 0
#define UREACT_VERSION_STR "0.9.0 wip"
#define UREACT_VERSION_STR "0.9.0"

#define UREACT_VERSION \
( UREACT_VERSION_MAJOR * 10000 + UREACT_VERSION_MINOR * 100 + UREACT_VERSION_PATCH )
Expand Down
6 changes: 3 additions & 3 deletions single_include/ureact/ureact_amalgamated.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
// http://www.boost.org/LICENSE_1_0.txt)
//
// ----------------------------------------------------------------
// Ureact v0.9.0 wip
// Generated: 2023-02-12 19:07:00.960740
// Ureact v0.9.0
// Generated: 2023-02-12 20:13:30.109790
// ----------------------------------------------------------------
// ureact - C++ header-only FRP library
// The library is heavily influenced by cpp.react - https://github.com/snakster/cpp.react
Expand All @@ -34,7 +34,7 @@
#define UREACT_VERSION_MAJOR 0
#define UREACT_VERSION_MINOR 9
#define UREACT_VERSION_PATCH 0
#define UREACT_VERSION_STR "0.9.0 wip"
#define UREACT_VERSION_STR "0.9.0"

#define UREACT_VERSION \
( UREACT_VERSION_MAJOR * 10000 + UREACT_VERSION_MINOR * 100 + UREACT_VERSION_PATCH )
Expand Down

0 comments on commit f3a2f82

Please sign in to comment.