Skip to content

Commit

Permalink
Fix projected naming
Browse files Browse the repository at this point in the history
  • Loading branch information
akutruff committed Aug 30, 2022
1 parent 75885c2 commit 26d5c3c
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions apps/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"private": true,
"version": "1.0.0",
"dependencies": {
"diagon": "^0.11.1",
"diagon-react": "^0.11.1",
"diagon": "^0.11.2",
"diagon-react": "^0.11.2",
"react": "~18.2.0",
"react-dom": "~18.2.0"
},
Expand Down
4 changes: 2 additions & 2 deletions apps/demo/src/Graph.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { areSame, elements } from 'diagon';
import { useMutator, useProjectionSnap, useSnap } from 'diagon-react';
import { useMutator, useProjectedSnap, useSnap } from 'diagon-react';
import React, { CSSProperties, FC, useState } from 'react';
import { RenderCounter } from './RenderCounter';

Expand Down Expand Up @@ -38,7 +38,7 @@ interface GraphNodeComponentProps {

export const GraphNodeComponent: FC<GraphNodeComponentProps> = React.memo(({ node }) => {
const [data, parentData, grandParent, children] = useSnap(node, node => [node.data, node.parent?.data, node.parent?.parent, elements(node.children)]);
const isLastChild = useProjectionSnap(node,
const isLastChild = useProjectedSnap(node,
node => [node.data, elements(node.parent?.children)],
node => areSame(node.parent?.children[node.parent?.children.length - 1], node));
const onUp = useMutator(node, moveNodeUp);
Expand Down
4 changes: 2 additions & 2 deletions apps/demo/src/PersonDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { areSame } from 'diagon';
import { useProjectionSnap, useSnap } from 'diagon-react';
import { useProjectedSnap, useSnap } from 'diagon-react';
import React, { FC, useRef } from 'react';
import { Person, useAppState } from './app';
import { RenderCounter } from './RenderCounter';
Expand All @@ -14,7 +14,7 @@ export const PersonDetails: FC<PersonDetailsProps> = React.memo(({ person, onCli

const renderCount = useRef(0);
renderCount.current += 1;
const isSelected = useProjectionSnap(state, state => state.selectedPerson, state => areSame(state.selectedPerson, person), [person]);
const isSelected = useProjectedSnap(state, state => state.selectedPerson, state => areSame(state.selectedPerson, person), [person]);
const [name, age] = useSnap(person, person => [person.name, person.age]);

return (
Expand Down
2 changes: 1 addition & 1 deletion packages/diagon-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "diagon-react",
"version": "0.11.1",
"version": "0.11.2",
"description": "Mutable state management for object graphs and React",
"homepage": "https://diagon.dev",
"repository": {
Expand Down
6 changes: 3 additions & 3 deletions packages/diagon-react/src/reactHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const createRecorderHooks = (recorder: SubscribingRecorder) => {

//Allows the subscription function to be different from the snap. This is important if you want to calculate values in the getSnap function
// and wish to return the previous value to prevent a re-render.
useProjectionSnap: <TState extends object, TSnap>(
useProjectedSnap: <TState extends object, TSnap>(
state: TState,
subscriber: (state: TState) => any,
selector: (state: TState, previousSnap?: TSnap) => TSnap,
Expand Down Expand Up @@ -149,12 +149,12 @@ export const useSnap = <TState extends object, TSnap>(state: TState, selector: (

//Allows the subscription function to be different from the snap. This is important if you want to calculate values in the getSnap function
// and wish to return the previous value to prevent a re-render.
export const useProjectionSnap = <TState extends object, TSnap>(
export const useProjectedSnap = <TState extends object, TSnap>(
state: TState,
subscriber: (state: TState) => any,
selector: (state: TState, previousSnap?: TSnap) => TSnap,
deps: Array<any> = []): TSnap =>
useStore().recorder.useProjectionSnap(state, subscriber, selector, deps);
useStore().recorder.useProjectedSnap(state, subscriber, selector, deps);

export const useSubscribedSnap = <TState extends object, TSnap>(
state: TState,
Expand Down
6 changes: 3 additions & 3 deletions packages/diagon-react/src/subscriptions.ui.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { act, fireEvent, render, RenderOptions } from '@testing-library/react';
import { createRecordingProxy, map_get, resetEnvironment, subscribe, subscribeDeep } from 'diagon';

import React, { FC, PropsWithChildren, ReactElement, useRef } from 'react';
import { createReactRecorder, ReactRecorder, StoreContext, StoreContextValue, useDeepSnap, useMutator, useProjectionSnap, useSnap, useSubscribedSnap } from '.';
import { createReactRecorder, ReactRecorder, StoreContext, StoreContextValue, useDeepSnap, useMutator, useProjectedSnap, useSnap, useSubscribedSnap } from '.';

const SubscriptionApp: FC<PropsWithChildren<StoreContextValue>> = ({ children, state, recorder }) => {
return (
Expand Down Expand Up @@ -34,7 +34,7 @@ describe('subscriptions', () => {
it.todo('is tested');
});

describe('useProjectionSnap', () => {
describe('useProjectedSnap', () => {
it('updates when single property changes', async () => {
const state = {
count: 0,
Expand All @@ -51,7 +51,7 @@ describe('subscriptions', () => {
const TestComponent: FC<{ state: State }> = ({ state }) => {
renderCount++;
// console.log('renderCount :>> ', renderCount);
const [ignore, count] = useProjectionSnap(state, stat => stat.count, (stat) => ['someRandomValue', stat.count]);
const [ignore, count] = useProjectedSnap(state, stat => stat.count, (stat) => ['someRandomValue', stat.count]);
expect(ignore).toEqual('someRandomValue');

return (
Expand Down
2 changes: 1 addition & 1 deletion packages/diagon/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "diagon",
"version": "0.11.1",
"version": "0.11.2",
"description": "Mutable state management for object graphs and React",
"homepage": "https://diagon.dev",
"repository": {
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"@docusaurus/preset-classic": "2.0.1",
"@mdx-js/react": "^1.6.22",
"clsx": "^1.2.1",
"diagon": "^0.11.1",
"diagon-react": "^0.11.1",
"diagon": "^0.11.2",
"diagon-react": "^0.11.2",
"prism-react-renderer": "^1.3.5",
"raw-loader": "^4.0.2",
"react": "^18.2.0",
Expand Down

1 comment on commit 26d5c3c

@vercel
Copy link

@vercel vercel bot commented on 26d5c3c Aug 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.