Repository navigation
OnChange moves here, OnSync, ReadOnly keeps its API (0.1.22) - #3
Merged
Merged
Conversation
…1.20 OnChange<fn>: fn(v) on every set(), as OneMenu had it. OnSync<fn>: on sync(), fn(v) when changed() is true, then Base::sync() takes the new copy. Host tests for both and an AVR size/cycle comparison against Data and Watch (test/avr_onsync.sh). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
OnSync reads Base::get() only, so it composes over a node that has get(), changed() and sync() but no Type (an ItemRef to a node). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A private base hid the wrapped value's whole API, including what an ItemDef reaches through its chain (using Base::enabled), so a ReadOnly could not be composed into an item. set() is deleted instead; get(), print(), changed() and sync() stay. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The shared smoke build compiles every test/*.cpp as a host program, and avr_onsync.cpp needs avr/io.h: it is a measurement, like the rest of benchmark/. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three small data components, in the order of the commits. 0.1.19 -> 0.1.22.
OnChange<fn>(moved from OneMenu)fn(v)on everyset(),vre-read viaget()afterBase::set(). Unchanged behaviour: OneMenu keepsusing oneData::OnChange;(follow-up PR in OneMenu) so its code and examples build unchanged. It is a data component, not a menu one.OnSync<fn>(new)Composed over a change tracker (
Watch,Dirty): onsync()it callsfn(value)whenchanged()is true, thenBase::sync(), so the tracker keeps its copy and is unchanged. For values that move outsideset()(an ISR, a hardware register, a sensor read). Needsget(),changed()andsync()of what it wraps; noType(so it composes over anItemRefto a node).DataDef<OnSync<publish>, Watch<Int>> d; // d.sync() calls publish(v) once per change, not on an equal setReadOnlypublic,set()deletedReadOnlyinherited its wrapped part privately, which hides the whole API of the base items, including what anItemDefreaches through its chain (using Base::enabled), so aReadOnlycould not be composed into an item.set()is now deleted;get(),print(),changed()andsync()stay.Tests (
test/test.cpp)OnChange(every set, also an equal one; chains through aWatch),OnSync(once per change, not atset(), not on an equal set, two in a row each fire once, overDirty: it starts dirty and an equalset()counts),ReadOnly(set()not callable,changed()/sync()kept; the existingReadOnlytests unchanged). g++ and clang++ with-Wall -Wextra -Wpedantic -Werror, and under ASan+UBSan.Cost (AVR, atmega328p -Os,
benchmark/avr_onsync.sh, simavr; eight sets)Data(set, read back)Watch, loop testschanged()and syncs by handWatch+OnSyncData+OnChangeOnSynccosts nothing over the hand-written loop (the two images are byte-identical in size and cycles). Headers only: nothing is instantiated unless used.🤖 Generated with Claude Code