Skip to content

Instantly share code, notes, and snippets.

@bnayae
bnayae / Cypher Builder Simple Statement.md
Last active February 2, 2020 13:44
Cypher Builder: Simple Statement

Option 1

.Pattern<Foo, Bar>((n , r) => n("n", "label", exclude: f => f.Name)) - r["r","type", convention: x => x != nameof(Bar.Date)] > n("n1")
.Pattern<Foo, Bar>((n , r) => n("n", "label", f => f.Name, f => f.Date)) - r["r","type", nameof(Foo.Date), nameof(Foo.Id)] > n("n1")

Option 2

.Pattern<Foo, Bar>((n , r) => n(n1 => n1.label, exclude: f => f.Name)) - r[r1 => r1.type, convention: x => x != nameof(Bar.Date)] > n("n1")
import { atomFamily } from ‘recoil’;
import { IRecoilId } from ‘../../interfaces’;
export const stateProductId = atomFamily<string, IRecoilId>({
key: 'state-product-id',
default: '',
});
import { SerializableParam } from 'recoil';
export interface IRecoilId
extends Readonly<Record<string, SerializableParam>> {
id: string;
journey: JourneyType;
}
export enum JourneyType {
order = 'order',
review = 'review',
}
export const stateTracking = atomFamily<string[], JourneyType>({
key: 'state-product-tracking',
default: [],
});
export const stateOrder = selectorFamily<IOrder, IRecoilId>({
key: 'state-order',
get: (familyKey) => ({ get }) => {
const { color, size, productId, count } = get(
waitForAll({
productId: stateProductId(familyKey),
color: stateColor(familyKey),
size: stateSize(familyKey),
count: stateCount(familyKey),
})
const key: IRecoilId = {
id,
journey,
};
const order = useRecoilValue(stateOrder(key));
import { DefaultValue } from 'recoil';
export const guardRecoilDefaultValue = (
candidate: any
): candidate is DefaultValue => {
if (candidate instanceof DefaultValue) return true;
return false;
};
if (guardRecoilDefaultValue(value)) {
reset(stateProductId(familyKey));
reset(stateColor(familyKey));
reset(stateSize(familyKey));
reset(stateCount(familyKey));
// remove from tracking
set(stateTracking(journey),
(prv) => [...prv.filter((m) => m !== id)]);
return; // no need for further handling
}
set(stateProductId(familyKey), value.productId);
set(stateColor(familyKey), value.color);
set(stateSize(familyKey), value.size);
set(stateCount(familyKey), value.count);
// track
set(stateTracking(journey), (prv) => {
return [...prv, id];
});
if (guardRecoilDefaultValue(value)) {
reset(stateProductId(familyKey));
reset(stateColor(familyKey));
reset(stateSize(familyKey));
reset(stateCount(familyKey));
// remove from tracking
set(stateTracking(journey),
(prv) => [...prv.filter((m) => m !== id)]);
return; // no need for further handling
}