change snippet markup for tutorial

This commit is contained in:
Yanick Champoux 2024-02-26 14:26:07 -05:00
parent c438847051
commit e3e9c9a24b
6 changed files with 18 additions and 18 deletions

View File

@ -1,4 +1,4 @@
/// [dux] /// --8<-- [start:dux]
import Updux from '../src/index.js'; import Updux from '../src/index.js';
import u from '@yanick/updeep-remeda'; import u from '@yanick/updeep-remeda';
@ -16,4 +16,4 @@ nextIdDux.addMutation('incNextId', () => id => id + 1)
export default nextIdDux.asDux; export default nextIdDux.asDux;
/// [dux] /// --8<-- [end:dux]

View File

@ -1,6 +1,6 @@
import { test, expect } from 'vitest'; import { test, expect } from 'vitest';
/// [tut1] /// --8<-- [start:tut1]
import Updux from 'updux'; import Updux from 'updux';
const todosDux = new Updux({ const todosDux = new Updux({
@ -10,13 +10,13 @@ const todosDux = new Updux({
} }
}); });
/// [tut1] /// ---8<-- [end:tut1]
/// [tut2] /// ---8<-- [start:tut2]
const store = todosDux.createStore(); const store = todosDux.createStore();
store.getState(); // { nextId: 1, todos: [] } store.getState(); // { nextId: 1, todos: [] }
/// [tut2] /// ---8<-- [end:tut2]
test("basic", () => { test("basic", () => {
expect(store.getState()).toEqual({ expect(store.getState()).toEqual({

View File

@ -1,6 +1,6 @@
import { test, expect } from 'vitest'; import { test, expect } from 'vitest';
/// [actions1] /// --8<-- [start:actions1]
import Updux, { createAction, withPayload } from 'updux'; import Updux, { createAction, withPayload } from 'updux';
type TodoId = number; type TodoId = number;
@ -18,12 +18,12 @@ const todosDux = new Updux({
todoDone, todoDone,
} }
}); });
/// [actions1] /// --8<-- [end:actions1]
/// [actions2] /// --8<-- [start:actions2]
todosDux.actions.addTodo('write tutorial'); todosDux.actions.addTodo('write tutorial');
// { type: 'addTodo', payload: 'write tutorial' } // { type: 'addTodo', payload: 'write tutorial' }
/// [actions2] /// --8<-- [end:actions2]
test("basic", () => { test("basic", () => {
expect(todosDux.actions.addTodo('write tutorial')).toEqual({ expect(todosDux.actions.addTodo('write tutorial')).toEqual({
@ -31,7 +31,7 @@ test("basic", () => {
}) })
}); });
/// [addMutation] /// --8<-- [start:addMutation]
todosDux.addMutation(addTodo, (description) => ({ todos, nextId }) => { todosDux.addMutation(addTodo, (description) => ({ todos, nextId }) => {
return { return {
todos: todos.concat({ description, id: nextId, done: false }), todos: todos.concat({ description, id: nextId, done: false }),
@ -55,7 +55,7 @@ const state = store.getState();
// ] // ]
// } // }
/// [addMutation] /// --8<-- [end:addMutation]
test("addMutation", () => { test("addMutation", () => {
expect(state).toEqual({ expect(state).toEqual({

View File

@ -2,7 +2,7 @@ import { test, expect } from 'vitest';
//process.env.UPDEEP_MODE = "dangerously_never_freeze"; //process.env.UPDEEP_MODE = "dangerously_never_freeze";
/// [effects-1] /// --8<-- [start:effects-1]
import u from '@yanick/updeep-remeda'; import u from '@yanick/updeep-remeda';
import * as R from 'remeda'; import * as R from 'remeda';
@ -53,7 +53,7 @@ todosDux.addEffect("addTodo", ({ getState, dispatch }) => next => action => {
const store = todosDux.createStore(); const store = todosDux.createStore();
store.dispatch.addTodo('write tutorial'); store.dispatch.addTodo('write tutorial');
/// [effects-1] /// --8<-- [end:effects-1]
test('basic', () => { test('basic', () => {
expect(store.getState()).toMatchObject({ expect(store.getState()).toMatchObject({

View File

@ -1,6 +1,6 @@
import { test, expect } from 'vitest'; import { test, expect } from 'vitest';
/// [mono] /// --8<-- [start:mono]
import Updux from '../src/index.js'; import Updux from '../src/index.js';
import u from '@yanick/updeep-remeda'; import u from '@yanick/updeep-remeda';
@ -51,7 +51,7 @@ todosDux.addEffect(
} }
); );
/// [mono] /// --8<-- [end:mono]
test('basic', () => { test('basic', () => {
const store = todosDux.createStore(); const store = todosDux.createStore();

View File

@ -1,6 +1,6 @@
import { test, expect } from 'vitest'; import { test, expect } from 'vitest';
/// [sel1] /// --8<-- [start:sel1]
import Updux from 'updux'; import Updux from 'updux';
const dux = new Updux({ const dux = new Updux({
@ -24,7 +24,7 @@ store.selectors.getById(state)(2); // = { id: 2, done: false }
store.getState.getDone(); // = [ { id: 1, done: true } ] store.getState.getDone(); // = [ { id: 1, done: true } ]
store.getState.getById(2); // = { id: 2, done: false } store.getState.getById(2); // = { id: 2, done: false }
/// [sel1] /// --8<-- [end:sel1]
test('selectors', () => { test('selectors', () => {
expect(dux.selectors.getDone(state)).toMatchObject([{ id: 1, done: true }]); expect(dux.selectors.getDone(state)).toMatchObject([{ id: 1, done: true }]);