-module(bright). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([init/2, update/3, compute/2, schedule/2, unwrap/1, data/1, computed/1, step/2, lazy_compute/3, lazy_schedule/3, start/2]). -export_type([bright/2]). -opaque bright(AHGB, AHGC) :: {bright, AHGB, AHGC, list(gleam@dynamic:dynamic_()), list(gleam@dynamic:dynamic_()), list(gleam@dynamic:dynamic_())}. -file("/Users/doctor/Workspace/bright/src/bright.gleam", 16). -spec are_dependencies_equal(any(), any()) -> boolean(). are_dependencies_equal(A, B) -> gleam_stdlib:identity(A) =:= gleam_stdlib:identity(B). -file("/Users/doctor/Workspace/bright/src/bright.gleam", 34). -spec init(AHGH, AHGI) -> bright(AHGH, AHGI). init(Data, Computed) -> {bright, Data, Computed, [], [], []}. -file("/Users/doctor/Workspace/bright/src/bright.gleam", 73). -spec update( bright(AHGW, AHGX), fun((AHGW) -> {AHGW, lustre@effect:effect(any())}), fun((bright(AHGW, AHGX)) -> bright(AHGW, AHGX)) ) -> bright(AHGW, AHGX). update(Bright, Update_, Next) -> {Data, Effects} = Update_(erlang:element(2, Bright)), Effects@1 = [gleam_stdlib:identity(Effects) | erlang:element(6, Bright)], _pipe = erlang:setelement(6, erlang:setelement(2, Bright, Data), Effects@1), Next(_pipe). -file("/Users/doctor/Workspace/bright/src/bright.gleam", 98). -spec compute(bright(AHHI, AHHJ), fun((AHHI, AHHJ) -> AHHJ)) -> bright(AHHI, AHHJ). compute(Bright, Compute_) -> _pipe = Compute_(erlang:element(2, Bright), erlang:element(3, Bright)), (fun(Computed) -> erlang:setelement(3, Bright, Computed) end)(_pipe). -file("/Users/doctor/Workspace/bright/src/bright.gleam", 121). -spec schedule( bright(AHHO, AHHP), fun((AHHO, AHHP) -> lustre@effect:effect(any())) ) -> bright(AHHO, AHHP). schedule(Bright, Schedule_) -> _pipe = Schedule_(erlang:element(2, Bright), erlang:element(3, Bright)), _pipe@1 = gleam_stdlib:identity(_pipe), _pipe@2 = gleam@list:prepend(erlang:element(6, Bright), _pipe@1), (fun(Effects) -> erlang:setelement(6, Bright, Effects) end)(_pipe@2). -file("/Users/doctor/Workspace/bright/src/bright.gleam", 207). -spec unwrap(bright(AHIM, AHIN)) -> {AHIM, AHIN}. unwrap(Bright) -> {erlang:element(2, Bright), erlang:element(3, Bright)}. -file("/Users/doctor/Workspace/bright/src/bright.gleam", 221). -spec data(bright(AHIR, any())) -> AHIR. data(Bright) -> erlang:element(2, Bright). -file("/Users/doctor/Workspace/bright/src/bright.gleam", 235). -spec computed(bright(any(), AHIX)) -> AHIX. computed(Bright) -> erlang:element(3, Bright). -file("/Users/doctor/Workspace/bright/src/bright.gleam", 257). -spec step( {bright(AHJB, AHJC), lustre@effect:effect(AHJF)}, fun((bright(AHJB, AHJC)) -> {AHJJ, lustre@effect:effect(AHJF)}) ) -> {AHJJ, lustre@effect:effect(AHJF)}. step(Bright, Next) -> {Bright@1, Effs} = Bright, {Model, Effs_} = Next(Bright@1), {Model, lustre@effect:batch([Effs, Effs_])}. -file("/Users/doctor/Workspace/bright/src/bright.gleam", 266). -spec lazy_wrap( bright(AHJM, AHJN), fun((AHJM) -> AHJQ), fun((bright(AHJM, AHJN), fun((AHJM, AHJN) -> AHJT)) -> bright(AHJM, AHJN)), fun((AHJM, AHJN, AHJQ) -> AHJT) ) -> bright(AHJM, AHJN). lazy_wrap(Bright, Selector, Setter, Compute_) -> Selected_data = Selector(erlang:element(2, Bright)), Selections = [gleam_stdlib:identity(Selected_data) | erlang:element(4, Bright)], Bright@1 = erlang:setelement(4, Bright, Selections), Compute_@1 = fun(Data, Computed) -> Compute_(Data, Computed, Selected_data) end, case erlang:element(5, Bright@1) of [] -> Setter(Bright@1, Compute_@1); [Value | Past_selections] -> _pipe = erlang:setelement(5, Bright@1, Past_selections), case are_dependencies_equal(Value, Selected_data) of true -> fun gleam@function:identity/1; false -> fun(_capture) -> Setter(_capture, Compute_@1) end end(_pipe) end. -file("/Users/doctor/Workspace/bright/src/bright.gleam", 155). -spec lazy_compute( bright(AHHW, AHHX), fun((AHHW) -> AHIA), fun((AHHW, AHHX, AHIA) -> AHHX) ) -> bright(AHHW, AHHX). lazy_compute(Bright, Selector, Compute_) -> lazy_wrap(Bright, Selector, fun compute/2, Compute_). -file("/Users/doctor/Workspace/bright/src/bright.gleam", 189). -spec lazy_schedule( bright(AHID, AHIE), fun((AHID) -> AHIH), fun((AHID, AHIE, AHIH) -> lustre@effect:effect(any())) ) -> bright(AHID, AHIE). lazy_schedule(Bright, Selector, Schedule_) -> lazy_wrap(Bright, Selector, fun schedule/2, Schedule_). -file("/Users/doctor/Workspace/bright/src/bright.gleam", 289). -spec panic_if_different_computations_count(list(any()), list(any())) -> nil. panic_if_different_computations_count(Old_computations, Computations) -> Count = erlang:length(Old_computations), gleam@bool:guard( Count =:= 0, nil, fun() -> Is_same_count = Count =:= erlang:length(Computations), gleam@bool:guard( Is_same_count, nil, fun() -> erlang:error(#{gleam_error => panic, message => <<"Memoized computed should be consistent over time, otherwise memo can not work."/utf8>>, module => <<"bright"/utf8>>, function => <<"panic_if_different_computations_count"/utf8>>, line => 297}) end ) end ). -file("/Users/doctor/Workspace/bright/src/bright.gleam", 49). -spec start(bright(AHGK, AHGL), fun((bright(AHGK, AHGL)) -> bright(AHGK, AHGL))) -> {bright(AHGK, AHGL), lustre@effect:effect(any())}. start(Bright, Next) -> Old_computations = erlang:element(5, Bright), New_data = Next(Bright), All_effects = begin _pipe = gleam_stdlib:identity(erlang:element(6, New_data)), _pipe@1 = bright_ffi:coerce(_pipe), lists:reverse(_pipe@1) end, panic_if_different_computations_count( Old_computations, erlang:element(4, New_data) ), Past_selections = lists:reverse(erlang:element(4, New_data)), _pipe@2 = erlang:setelement( 6, erlang:setelement( 4, erlang:setelement(5, New_data, Past_selections), [] ), [] ), gleam@pair:new(_pipe@2, lustre@effect:batch(All_effects)).