Skip to content

Commit

Permalink
feat: Initial effect type (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy-xr authored Oct 2, 2024
1 parent f756f36 commit 03f115a
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 16 deletions.
2 changes: 1 addition & 1 deletion examples/hello/hello.fs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ let tick model (tick: Time.FrameTime) =
|> handleCollisionWithPaddle model.paddle1
|> handleCollisionWithPaddle model.paddle2)

( { model with ball = newBall; counter = model.counter + 3 }, Effect.none )
( { model with ball = newBall; counter = model.counter + 3 }, Effect.none () )

open Fable.Core.Rust

Expand Down
15 changes: 15 additions & 0 deletions runtime/functor-runtime-common/src/effect.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#[derive(Clone)]
pub enum Effect<T: Clone + 'static> {
None,
Wrapped(T),
}

impl<T: Clone + 'static> Effect<T> {
pub fn none() -> Effect<T> {
Effect::None
}

pub fn wrapped(data: T) -> Effect<T> {
Effect::Wrapped(data)
}
}
2 changes: 2 additions & 0 deletions runtime/functor-runtime-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ impl OpaqueState {

pub mod animation;
pub mod asset;
mod effect;
mod frame_time;
pub mod geometry;
pub mod io;
Expand All @@ -63,6 +64,7 @@ mod shader;
mod shader_program;
pub mod texture;

pub use effect::*;
pub use frame_time::*;
pub use render_context::*;
pub use scene3d::*;
Expand Down
12 changes: 7 additions & 5 deletions src/Functor.Game/Effect.fs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
namespace Functor
open Fable.Core

type effect<'msg> =
| Noop
| Function of (unit -> unit)
| FunctionWithDispatch of (('msg -> unit) -> unit)
[<Erase; Emit("functor_runtime_common::Effect<$0>")>] type effect<'msg> = | Noop

module Effect =
let none = Noop
[<Emit("functor_runtime_common::Effect::none()")>]
let none (): effect<_> = nativeOnly

[<Emit("functor_runtime_common::Effect::wrapped($0)")>]
let wrapped a: 'a -> effect<'a> = nativeOnly
6 changes: 0 additions & 6 deletions src/Functor.Game/Effect.fsi

This file was deleted.

1 change: 0 additions & 1 deletion src/Functor.Game/Functor.Game.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="Effect.fsi" />
<Compile Include="Effect.fs" />
<Compile Include="Math/Angle.fs" />
<Compile Include="Math/Vector2.fs" />
Expand Down
6 changes: 3 additions & 3 deletions src/Functor.Game/Game.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ open Fable.Core
module GameBuilder =

let local initialState =
let update model msg = (model, Effect.none)
let tick model tick = (model, Effect.none)
let update model msg = (model, Effect.none ())
let tick model tick = (model, Effect.none ())
let draw3d model frametime = Graphics.Scene3D.cube()
let input model input = (model, Effect.none)
let input model input = (model, Effect.none ())
{ initialState = initialState; update = update; tick = tick; input = input; draw3d = draw3d}

let update<'model, 'msg> (f: UpdateFn<'model, 'msg>) (game: Game<'model, 'msg>) =
Expand Down

0 comments on commit 03f115a

Please sign in to comment.