Slide 28
Slide 28 text
© 2023 Leverages Co., Ltd.
今さっきのDIのコードとそんなに変わらないのでは?
28
async function test() {
const runnable = Effect.provideService(
Effect.provideService(
Effect.provideService(autoTurnOnAC(1), DBConnection, {
executeQuery: (query: string) =>
Effect.succeed([{ temperatureThreshold: 20, wakeUpHour: 8 }]),
}),
RemoteController,
{
getTemperature: () => Effect.succeed(20),
turnOnAC: () => Effect.succeed(undefined),
}
),
Clock,
{
getNow: () => Effect.succeed(new Date("2021-01-01T07:00:00Z")),
}
);
const r = await Effect.runPromise(runnable);
assert(r === "TurnOn");
}
function test() {
container.register("Database", {
useValue: {
executeQuery: () =>
Promise.resolve([{ temperatureThreshold: 20, wakeUpHour: 8 }]),
},
});
container.register("RemoteController", {
useValue: {
getTemperature: () => Promise.resolve(20),
turnOnAC: () => Promise.resolve(),
},
});
container.register("Clock", {
useValue: {
getNow: () => new Date("2021-01-01T07:00:00Z"),
},
});
const autoACController = container.resolve(AutoACController);
autoACController.autoTurnOnAC(1).then((result) => {
assert(result === true);
});
}