@felte/core
Advanced tools
Comparing version 1.0.0-next.6 to 1.0.0-next.7
@@ -0,2 +1,9 @@ | ||
import { Readable } from "svelte/store"; | ||
import { Obj, Stores, FormConfig, Form, FormConfigWithTransformFn, FormConfigWithoutTransformFn, StoreFactory, UnknownStores, KnownStores, Helpers, UnknownHelpers, KnownHelpers } from "@felte/common"; | ||
type Store<Data> = Readable<Data> | { | ||
subscribe(subscriber: (value: Data) => void): { | ||
unsubscribe(): void; | ||
}; | ||
}; | ||
declare function get<Data>(store: Store<Data>): Data; | ||
type FailResponse = Omit<Response, "ok"> & { | ||
@@ -14,2 +21,3 @@ ok: false; | ||
cleanup(): void; | ||
startStores(): () => void; | ||
}; | ||
@@ -19,4 +27,4 @@ declare function createForm<Data extends Obj = Obj, Ext extends Obj = Obj, StoreExt = Record<string, any>>(config: FormConfigWithTransformFn<Data> & Ext, adapters: Adapters<StoreExt>): CoreForm<Data> & UnknownHelpers<Data> & UnknownStores<Data, StoreExt>; | ||
declare function createForm<Data extends Obj = Obj, Ext extends Obj = Obj, StoreExt = Record<string, any>>(config: FormConfig<Data> & Ext, adapters: Adapters<StoreExt>): CoreForm<Data> & Helpers<Data> & Stores<Data, StoreExt>; | ||
export { FelteSubmitError, Adapters, CoreForm, createForm }; | ||
export { get as getValueFromStore, FelteSubmitError, Adapters, CoreForm, createForm }; | ||
export * from '@felte/common'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -5,2 +5,12 @@ 'use strict'; | ||
function subscribe(store, ...callbacks) { | ||
const unsub = store.subscribe(...callbacks); | ||
return unsub.unsubscribe ? () => unsub.unsubscribe() : unsub; | ||
} | ||
function get(store) { | ||
let value = undefined; | ||
subscribe(store, (_) => (value = _))(); | ||
return value; | ||
} | ||
/** @ignore */ | ||
@@ -505,12 +515,2 @@ function _some(obj, pred) { | ||
function subscribe(store, ...callbacks) { | ||
const unsub = store.subscribe(...callbacks); | ||
return unsub.unsubscribe ? () => unsub.unsubscribe() : unsub; | ||
} | ||
function get(store) { | ||
let value = undefined; | ||
subscribe(store, (_) => (value = _))(); | ||
return value; | ||
} | ||
class FelteSubmitError extends Error { | ||
@@ -1059,31 +1059,34 @@ constructor(message, response) { | ||
} | ||
const dataUnsubscriber = data.subscribe(($data) => { | ||
validateErrors($data); | ||
validateWarnings($data); | ||
}); | ||
let touchedValue = initialTouched; | ||
let errorsValue = initialErrors; | ||
let firstCalled = false; | ||
const errorsUnsubscriber = errors.subscribe(($errors) => { | ||
if (!firstCalled) { | ||
firstCalled = true; | ||
isValid.set(!config.validate); | ||
function start() { | ||
const dataUnsubscriber = data.subscribe(($data) => { | ||
validateErrors($data); | ||
validateWarnings($data); | ||
}); | ||
let touchedValue = initialTouched; | ||
let errorsValue = initialErrors; | ||
let firstCalled = false; | ||
const errorsUnsubscriber = errors.subscribe(($errors) => { | ||
if (!firstCalled) { | ||
firstCalled = true; | ||
isValid.set(!config.validate); | ||
} | ||
else { | ||
const hasErrors = deepSome($errors, (error) => !!error); | ||
isValid.set(!hasErrors); | ||
} | ||
errorsValue = $errors; | ||
const mergedErrors = _mergeWith($errors, touchedValue, errorFilterer); | ||
filteredErrorsSet(mergedErrors); | ||
}); | ||
const touchedUnsubscriber = touched.subscribe(($touched) => { | ||
touchedValue = $touched; | ||
const mergedErrors = _mergeWith(errorsValue, $touched, errorFilterer); | ||
filteredErrorsSet(mergedErrors); | ||
}); | ||
function cleanup() { | ||
dataUnsubscriber(); | ||
errorsUnsubscriber(); | ||
touchedUnsubscriber(); | ||
} | ||
else { | ||
const hasErrors = deepSome($errors, (error) => !!error); | ||
isValid.set(!hasErrors); | ||
} | ||
errorsValue = $errors; | ||
const mergedErrors = _mergeWith($errors, touchedValue, errorFilterer); | ||
filteredErrorsSet(mergedErrors); | ||
}); | ||
const touchedUnsubscriber = touched.subscribe(($touched) => { | ||
touchedValue = $touched; | ||
const mergedErrors = _mergeWith(errorsValue, $touched, errorFilterer); | ||
filteredErrorsSet(mergedErrors); | ||
}); | ||
function cleanup() { | ||
dataUnsubscriber(); | ||
errorsUnsubscriber(); | ||
touchedUnsubscriber(); | ||
return cleanup; | ||
} | ||
@@ -1100,3 +1103,4 @@ filteredErrors.set = errors.set; | ||
isDirty, | ||
cleanup, | ||
cleanup: config.preventStoreStart ? () => undefined : start(), | ||
start, | ||
}; | ||
@@ -1149,3 +1153,3 @@ } | ||
let currentExtenders = []; | ||
const { isSubmitting, data, errors, warnings, touched, isValid, isDirty, cleanup, } = createStores(adapters.storeFactory, config); | ||
const { isSubmitting, data, errors, warnings, touched, isValid, isDirty, cleanup, start, } = createStores(adapters.storeFactory, config); | ||
const originalUpdate = data.update; | ||
@@ -1232,3 +1236,3 @@ const originalSet = data.set; | ||
createSubmitHandler, | ||
cleanup }, helpers.public); | ||
cleanup, startStores: start }, helpers.public); | ||
} | ||
@@ -1261,2 +1265,3 @@ | ||
exports.getValue = getValue; | ||
exports.getValueFromStore = get; | ||
exports.isElement = isElement; | ||
@@ -1263,0 +1268,0 @@ exports.isFieldSetElement = isFieldSetElement; |
{ | ||
"name": "@felte/core", | ||
"version": "1.0.0-next.6", | ||
"version": "1.0.0-next.7", | ||
"description": "Core package for FelteJS", | ||
@@ -51,3 +51,3 @@ "main": "dist/index.js", | ||
}, | ||
"readme": "# @felte/core\n\n[![Bundle size](https://img.shields.io/bundlephobia/min/@felte/core)](https://bundlephobia.com/result?p=@felte/core)\n[![NPM Version](https://img.shields.io/npm/v/@felte/core)](https://www.npmjs.com/package/@felte/core)\n\nThe core package containing the main functionality of Felte. This allows to make Felte compatible with multiple frameworks or vanilla javascript. More documenttion on this pending.\n" | ||
"readme": "# @felte/core\n\n[![Bundle size](https://img.shields.io/bundlephobia/min/@felte/core)](https://bundlephobia.com/result?p=@felte/core)\n[![NPM Version](https://img.shields.io/npm/v/@felte/core)](https://www.npmjs.com/package/@felte/core)\n\nThe core package containing the main functionality of Felte. This allows to make Felte compatible with multiple frameworks or vanilla javascript. More documenttion on this pending.\n\nSince this package is _bundled_ with other packages, breaking changes might occur in between minor versions, specially if they're required to _prevent_ breaking changes on the other packages.\n" | ||
} |
@@ -7,1 +7,3 @@ # @felte/core | ||
The core package containing the main functionality of Felte. This allows to make Felte compatible with multiple frameworks or vanilla javascript. More documenttion on this pending. | ||
Since this package is _bundled_ with other packages, breaking changes might occur in between minor versions, specially if they're required to _prevent_ breaking changes on the other packages. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
287762
2475
9