Comparing version 1.0.4 to 1.0.5
@@ -1,2 +0,1 @@ | ||
import { Draft } from 'immer'; | ||
export declare class RecordOperator<T extends Record<string, any>> { | ||
@@ -56,3 +55,2 @@ target: T; | ||
export declare function entity<T>(target: T): RecordOperator<T>; | ||
export declare function sliceSelector<T extends Record<string, any>>(selector: (model: T) => Draft<T>): (record: T) => RecordOperator<Draft<T>>; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.sliceSelector = exports.entity = exports.CollectionOperator = exports.RecordOperator = void 0; | ||
exports.entity = exports.CollectionOperator = exports.RecordOperator = void 0; | ||
function copy(obj1, obj2) { | ||
@@ -112,5 +112,1 @@ for (var key in obj1) { | ||
exports.entity = entity; | ||
function sliceSelector(selector) { | ||
return function (record) { return entity(selector(record)); }; | ||
} | ||
exports.sliceSelector = sliceSelector; |
@@ -12,5 +12,5 @@ import { Draft } from 'immer'; | ||
readonly entity: typeof entity; | ||
readonly sliceEntity: <G extends (record: T) => any>(fn: G) => Operator<G>; | ||
readonly sliceEntity: <G extends (record: T) => any>(slice: G) => (record: T) => Operator<G>; | ||
readonly draft: (drafter: (args: Draft<T>) => void) => void; | ||
} & Extensions]; | ||
export {}; |
@@ -33,5 +33,5 @@ "use strict"; | ||
nextState, | ||
__assign({ entity: entity_1.entity, sliceEntity: function (fn) { return entity_1.entity(fn(nextState)); }, draft: draft }, extensions({ draft: draft, initialState: record, nextState: nextState })) | ||
__assign({ entity: entity_1.entity, sliceEntity: function (slice) { return function (record) { return entity_1.entity(slice(record)); }; }, draft: draft }, extensions({ draft: draft, initialState: record, nextState: nextState })) | ||
]; }, [nextState, extensions]); | ||
} | ||
exports.useData = useData; |
{ | ||
"name": "drifting", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "A fully typescript typed react solution for interacting with complex data-structures", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
import { renderHook, act } from '@testing-library/react-hooks' | ||
import { useData } from '../useData' | ||
import { useData } from '..' | ||
@@ -457,4 +457,7 @@ const record = { | ||
recordUser.draft(user => { | ||
user.id = 'altered' | ||
controller.draft(record => { | ||
recordUser(record) | ||
.draft(user => { | ||
user.id = 'altered' | ||
}) | ||
}) | ||
@@ -484,9 +487,10 @@ }) | ||
const recordUserCollection = controller.sliceEntity(record => record.user.collection) | ||
recordUserCollection | ||
.select((budget) => budget.id === '1') | ||
.draft(budget => { | ||
budget.name = 'altered' | ||
}) | ||
controller.draft(user => { | ||
recordUserCollection(user) | ||
.select((budget) => budget.id === '1') | ||
.draft(budget => { | ||
budget.name = 'altered' | ||
}) | ||
}) | ||
}) | ||
@@ -493,0 +497,0 @@ |
@@ -1,3 +0,1 @@ | ||
import { Draft } from 'immer' | ||
function copy<T extends Record<string, any>> (obj1: T, obj2: T) { | ||
@@ -118,5 +116,1 @@ for (let key in obj1) { | ||
} | ||
export function sliceSelector<T extends Record<string, any>> (selector: (model: T) => Draft<T>) { | ||
return (record: T) => entity(selector(record)) | ||
} |
@@ -47,3 +47,5 @@ import { useState, useEffect, useContext, useMemo } from 'react' | ||
entity, | ||
sliceEntity: <G extends (record: T) => any>(fn: G) => entity(fn(nextState)) as Operator<G>, | ||
sliceEntity: <G extends (record: T) => any>(slice: G) => ( | ||
record: T | ||
) => entity(slice(record)) as Operator<G>, | ||
draft, | ||
@@ -50,0 +52,0 @@ ...extensions({ draft, initialState: record, nextState }), |
35050
850