@acanto/core-cart
Advanced tools
Comparing version 0.0.8 to 0.0.9
82
index.ts
@@ -6,8 +6,9 @@ import { | ||
} from "@acanto/core-ajax/laravel"; | ||
import { $$, forEach, setDataAttr, listen, toArray } from "@acanto/core-dom"; | ||
import { isUserOrGuest } from "@acanto/core-auth"; | ||
import { $$, forEach, toArray, setDataAttr, listen } from "@acanto/core-dom"; | ||
import { | ||
// callHookSafely, | ||
getScopedRoot, | ||
isArray, | ||
isUndefined, | ||
isAuthenticated, | ||
} from "@acanto/core-helpers"; | ||
@@ -19,3 +20,3 @@ import { Emitter } from "@acanto/core-helpers/Emitter"; | ||
getItemData, | ||
getItemsById, | ||
eachItemWithId, | ||
} from "@acanto/core-helpers/item"; | ||
@@ -27,3 +28,3 @@ | ||
GET: { | ||
response: $response_item[]; | ||
response: boolean | $response_item[]; | ||
}; | ||
@@ -114,3 +115,3 @@ }; | ||
) { | ||
forEach(getItemsById(id), ($item) => { | ||
eachItemWithId(id, ($item) => { | ||
setDataAttr($item, ATTR_STATUS, status); | ||
@@ -156,11 +157,2 @@ | ||
export function get() { | ||
if (!isAuthenticated()) { | ||
if (__DEV__) { | ||
console.warn( | ||
"[@acanto/core-cart] called 'get' with unauthenticated user" | ||
); | ||
} | ||
return; | ||
} | ||
const request = laravelGet<Cart.$requests["/cart"]["GET"]["response"]>( | ||
@@ -172,5 +164,7 @@ ENDPOINT | ||
store = {}; | ||
data.forEach((item) => { | ||
store[item.id] = true; | ||
}); | ||
if (isArray(data)) { | ||
data.forEach((item) => { | ||
store[item.id] = true; | ||
}); | ||
} | ||
// }).catch(() => { | ||
@@ -186,11 +180,2 @@ }); | ||
export function add(data: Cart.Item) { | ||
if (!isAuthenticated()) { | ||
if (__DEV__) { | ||
console.warn( | ||
"[@acanto/core-cart] called 'add' with unauthenticated user" | ||
); | ||
} | ||
return; | ||
} | ||
emit("updating", { data }); | ||
@@ -213,11 +198,2 @@ | ||
export function remove(data: Cart.Item) { | ||
if (!isAuthenticated()) { | ||
if (__DEV__) { | ||
console.warn( | ||
"[@acanto/core-cart] called 'remove' with unauthenticated user" | ||
); | ||
} | ||
return; | ||
} | ||
emit("updating", { data }); | ||
@@ -267,7 +243,2 @@ | ||
if (!isAuthenticated()) { | ||
emit("add:unauth", args); | ||
return; | ||
} | ||
setStatus(data, "loading"); | ||
@@ -303,4 +274,2 @@ // callHookSafely(hooks, "before", args); | ||
}); | ||
// watchItemProperties(); | ||
} | ||
@@ -323,7 +292,2 @@ | ||
if (!isAuthenticated()) { | ||
emit("remove:unauth", args); | ||
return; | ||
} | ||
setStatus(data, "loading"); | ||
@@ -355,3 +319,3 @@ // callHookSafely(hooks, "before", args); | ||
console.error( | ||
`The clicked whislist btn is not inside an element with 'data-${ATTR_ITEM}'.` | ||
`The clicked cart btn remove is not inside an element with 'data-${ATTR_ITEM}'.` | ||
); | ||
@@ -367,18 +331,10 @@ } | ||
export function init(rooter?: Rooter) { | ||
if (!isAuthenticated()) { | ||
if (__DEV__) { | ||
console.info( | ||
"[@acanto/core-cart] called 'init' with unauthenticated user" | ||
); | ||
} | ||
return; | ||
if (isUserOrGuest()) { | ||
const request = get(); | ||
request.then(() => { | ||
hydrate(rooter); | ||
}); | ||
return request; | ||
} | ||
const request = get(); | ||
request.then(() => { | ||
hydrate(rooter); | ||
}); | ||
return request; | ||
} | ||
@@ -385,0 +341,0 @@ |
{ | ||
"name": "@acanto/core-cart", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"author": "Acanto <info@acanto.net> (https://acanto.agency/)", | ||
@@ -15,5 +15,6 @@ "license": "ISC", | ||
"dependencies": { | ||
"@acanto/core-ajax": "^0.0.18", | ||
"@acanto/core-ajax": "^0.0.19", | ||
"@acanto/core-auth": "^0.0.48", | ||
"@acanto/core-dom": "^0.0.11", | ||
"@acanto/core-helpers": "^0.0.21" | ||
"@acanto/core-helpers": "^0.0.22" | ||
}, | ||
@@ -23,3 +24,3 @@ "sideEffects": [ | ||
], | ||
"gitHead": "ed8810b5ab87625aa4afad694f054aa65cdc04db" | ||
"gitHead": "c28d1d57c5d4532acad90aa4b85e4b739c13e1fc" | ||
} |
8885
4
296
+ Added@acanto/core-auth@^0.0.48
+ Added@acanto/core-ajax@0.0.19(transitive)
+ Added@acanto/core-auth@0.0.48(transitive)
+ Added@acanto/core-forms@0.0.33(transitive)
+ Added@acanto/core-helpers@0.0.22(transitive)
- Removed@acanto/core-ajax@0.0.18(transitive)
- Removed@acanto/core-helpers@0.0.21(transitive)
Updated@acanto/core-ajax@^0.0.19
Updated@acanto/core-helpers@^0.0.22