@logux/client
Advanced tools
Comparing version 0.12.1 to 0.13.0
import { isFirstOlder } from '@logux/core' | ||
import { createMap } from 'nanostores' | ||
import { createMap, startEffect } from 'nanostores' | ||
@@ -99,2 +99,3 @@ import { track } from '../track/index.js' | ||
let endEffect = startEffect() | ||
filterStore.loading = new Promise((resolve, reject) => { | ||
@@ -119,2 +120,3 @@ async function loadAndCheck(child) { | ||
filterStore.setKey('isLoading', false) | ||
endEffect() | ||
resolve() | ||
@@ -155,2 +157,3 @@ } | ||
filterStore.setKey('isLoading', false) | ||
endEffect() | ||
resolve() | ||
@@ -174,2 +177,3 @@ } | ||
} | ||
endEffect() | ||
resolve() | ||
@@ -181,2 +185,3 @@ } | ||
reject(e) | ||
endEffect() | ||
}) | ||
@@ -183,0 +188,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { defineMap, getValue, clean } from 'nanostores' | ||
import { defineMap, getValue, clean, startEffect, effect } from 'nanostores' | ||
import { isFirstOlder } from '@logux/core' | ||
@@ -82,6 +82,13 @@ | ||
} else { | ||
let endEffect = startEffect() | ||
let loadingResolve, loadingReject | ||
store.loading = new Promise((resolve, reject) => { | ||
loadingResolve = resolve | ||
loadingReject = reject | ||
loadingResolve = () => { | ||
resolve() | ||
endEffect() | ||
} | ||
loadingReject = e => { | ||
reject(e) | ||
endEffect() | ||
} | ||
}) | ||
@@ -177,8 +184,10 @@ if (store.remote) { | ||
async (action, meta) => { | ||
try { | ||
await track(client, meta.id) | ||
removeReasons() | ||
} catch { | ||
client.log.changeMeta(meta.id, { reasons: [] }) | ||
} | ||
await effect(async () => { | ||
try { | ||
await track(client, meta.id) | ||
removeReasons() | ||
} catch { | ||
await client.log.changeMeta(meta.id, { reasons: [] }) | ||
} | ||
}) | ||
}, | ||
@@ -192,2 +201,3 @@ { id } | ||
async (action, meta) => { | ||
let endEffect = startEffect() | ||
changeIfLast(store, action.fields, meta) | ||
@@ -203,2 +213,3 @@ try { | ||
} | ||
endEffect() | ||
} catch { | ||
@@ -240,2 +251,3 @@ client.log.changeMeta(meta.id, { reasons: [] }) | ||
} | ||
endEffect() | ||
}) | ||
@@ -290,18 +302,24 @@ } | ||
export function createSyncMap(client, Builder, fields) { | ||
let id = fields.id | ||
delete fields.id | ||
let indexes = { indexes: getIndexes(Builder.plural, id) } | ||
function addSyncAction(client, Builder, action) { | ||
let meta = { indexes: getIndexes(Builder.plural, action.id) } | ||
if (!Builder.remote) { | ||
action.type += 'd' | ||
} | ||
if (Builder.remote) { | ||
return client | ||
.sync({ type: `${Builder.plural}/create`, id, fields }, indexes) | ||
.catch(() => {}) | ||
return effect(() => client.sync(action, meta)) | ||
} else { | ||
return client.log.add( | ||
{ type: `${Builder.plural}/created`, id, fields }, | ||
indexes | ||
) | ||
return effect(() => client.log.add(action, meta)) | ||
} | ||
} | ||
export function createSyncMap(client, Builder, fields) { | ||
let id = fields.id | ||
delete fields.id | ||
return addSyncAction(client, Builder, { | ||
type: `${Builder.plural}/create`, | ||
id, | ||
fields | ||
}) | ||
} | ||
export async function buildNewSyncMap(client, Builder, fields) { | ||
@@ -321,3 +339,3 @@ let id = fields.id | ||
if (Builder.remote) meta.sync = true | ||
await client.log.add(action, meta) | ||
await effect(() => client.log.add(action, meta)) | ||
@@ -330,21 +348,7 @@ let store = Builder(id, client, action, meta) | ||
if (value) fields = { [fields]: value } | ||
if (Builder.remote) { | ||
return client.sync( | ||
{ | ||
type: `${Builder.plural}/change`, | ||
id, | ||
fields | ||
}, | ||
{ indexes: getIndexes(Builder.plural, id) } | ||
) | ||
} else { | ||
return client.log.add( | ||
{ | ||
type: `${Builder.plural}/changed`, | ||
id, | ||
fields | ||
}, | ||
{ indexes: getIndexes(Builder.plural, id) } | ||
) | ||
} | ||
return addSyncAction(client, Builder, { | ||
type: `${Builder.plural}/change`, | ||
id, | ||
fields | ||
}) | ||
} | ||
@@ -359,13 +363,6 @@ | ||
export function deleteSyncMapById(client, Builder, id) { | ||
if (Builder.remote) { | ||
return client.sync( | ||
{ type: `${Builder.plural}/delete`, id }, | ||
{ indexes: getIndexes(Builder.plural, id) } | ||
) | ||
} else { | ||
return client.log.add( | ||
{ type: `${Builder.plural}/deleted`, id }, | ||
{ indexes: getIndexes(Builder.plural, id) } | ||
) | ||
} | ||
return addSyncAction(client, Builder, { | ||
type: `${Builder.plural}/delete`, | ||
id | ||
}) | ||
} | ||
@@ -372,0 +369,0 @@ |
{ | ||
"name": "@logux/client", | ||
"version": "0.12.1", | ||
"version": "0.13.0", | ||
"description": "Logux base components to build web client", | ||
@@ -31,3 +31,3 @@ "keywords": [ | ||
"@logux/core": "^0.7.0", | ||
"nanostores": "^0.3.0", | ||
"nanostores": "^0.4.1", | ||
"preact": ">=10.0.0", | ||
@@ -53,3 +53,3 @@ "react": ">=16.8.0", | ||
"dependencies": { | ||
"@logux/actions": "^0.2.0", | ||
"@logux/actions": "^0.2.1", | ||
"fast-json-stable-stringify": "^2.1.0", | ||
@@ -56,0 +56,0 @@ "nanodelay": "^2.0.0", |
@@ -1,3 +0,2 @@ | ||
import { unstable_batchedUpdates } from 'react-dom' | ||
import { useStore } from 'nanostores/react' | ||
import { useStore, batch } from 'nanostores/react' | ||
import { getValue } from 'nanostores' | ||
@@ -51,3 +50,3 @@ import React from 'react' | ||
let unbind = store.listen(() => { | ||
unstable_batchedUpdates(() => { | ||
batch(() => { | ||
forceRender({}) | ||
@@ -54,0 +53,0 @@ }) |
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
146876
+ Addednanostores@0.4.9(transitive)
- Removednanostores@0.3.3(transitive)
Updated@logux/actions@^0.2.1