List of Svelte state stores? - data-binding

i'm new to svelte and state management in general so bear with me.
I currently have a store that models a full workout (todaysWorkout). I have some custom logic that I'd like to perform each time a change is made to the a field in an element in routine_details list. As there are more routines in the routines list and more routine_details in the routine_details list, finding the specific change in a big store will become costly.
Is there any way to have each element in the routine_details lists be its own state stores so I can add custom logic to the set function for each of those elements?
Hope this question makes sense. Thank you!
sample of the current todaysWorkout store
{
"name": "pushup-pullup workout",
"routines": [
{
"name": "pushup",
"routine_details": [
{
"reps": 30,
"status": "InProgress",
"weight": 0,
"index": 2,
"id": "3638090c-988e-44d3-8248-63ce42046fe3"
},
{
"reps": 15,
"status": "Completed",
"weight": 0,
"index": 1,
"id": "938dec96-dba0-4b8e-b260-50098fd3bb21"
},
{
"reps": 20,
"status": "Completed",
"weight": 0,
"index": 0,
"id": "537a24e5-c91b-474e-aef2-913d7dd09e54"
}
]
},
{
"name": "pullup",
"routine_details": [
{
"reps": 6,
"status": "NotStarted",
"weight": 0,
"index": 0,
"id": "b99016ce-0225-47ee-9f1c-f1f45bd984e8"
},
{
"reps": 6,
"status": "NotStarted",
"weight": 0,
"index": 4,
"id": "9a456c77-8866-449a-a31c-18c923be135e"
},
{
"reps": 6,
"status": "NotStarted",
"weight": 0,
"index": 3,
"id": "b2c4cdab-2cfd-47b4-97b2-209c04415066"
},
{
"reps": 7,
"status": "NotStarted",
"weight": 0,
"index": 2,
"id": "70d843a4-abf1-4d81-8d5f-77bc2bd18462"
},
{
"reps": 7,
"status": "NotStarted",
"weight": 0,
"index": 1,
"id": "2b477d0e-0b49-435f-b793-9ec082a4d9d9"
},
{
"reps": 6,
"status": "NotStarted",
"weight": 0,
"index": 5,
"id": "d7c47939-676d-48bb-a3c1-71da1d853e09"
}
]
}
]
}
what i've tried
I tried a dumbed down version of my ideal which is a list of stateful routines derived from the larger store todaysWorkout.
...
export const todaysWorkout = writable<WorkoutInstance | undefined>();
function createRoutine(routine: RoutineSession): Writable<RoutineSession> {
const { subscribe, set } = writable<RoutineSession | undefined>(routine);
return {
subscribe,
set: (value: RoutineSession) => {
set(value);
// perform custom logic here
}
} as Writable<RoutineSession>;
}
export const todaysRoutines = derived(todaysWorkout, ($todaysWorkout) => $todaysWorkout?.routines.map((routine) => createRoutine(routine)));
I can bind routines that exist in the todaysWorkout store fine and can see the store updating
{#each $todaysWorkout?.routines || [] as routine}
<RoutineChecklist bind:routine />
{/each}
but when I try to use the derived store instead I no longer see the store updating.
{#each $todaysRoutines || [] as routine}
<RoutineChecklist bind:routine />
{/each}

Related

How to create widget in a single AWS Cloud Watch dashboard for a list of instances

Terraform (aws provider) beginner here. I am trying to create aws-cloudwatch widget that graphs CPU Utilization for 3 instances. However, I only get one graph generated for the last instance in the list instead three graphs on one widget! How can I fix this please or get this How can I get this code to create CPUUtilisation graph for three instances on the same widget? Thank you
variable "targets" {
default = ["i-086e06769b6c67665","i-0477b6f25ad155290","i-0e6320273511d17dc"]
}
resource "aws_cloudwatch_dashboard" "ec2" {
dashboard_name = "ec2-test-dashboard"
count = length(var.targets)
dashboard_body = <<EOF
{
"widgets": [
{
"type": "metric",
"x": 0,
"y": 0,
"width": 17,
"height": 8,
"properties": {
"metrics": [
["AWS/EC2","CPUUtilization","InstanceId","${(var.targets[count.index])}"]
],
"title": "EC2 dashboard: CPUUtilization",
"stat": "Average",
"period": 300,
"stacked": false,
"view": "timeSeries",
"region": "eu-west-1",
"annotations": {
"horizontal": [
{
"label": "critical range",
"value": 10
}
]
},
"legend": {
"position": "right"
}
}
}
]
}
EOF
}

Mixed regular and copied properties in ARM template

Using property iteration we can multiply properties in ARM resource. But how can I mix these copied properties with others that are typed explicitly?
What I expect might look like this snippet (of course it's incorrect because "probes" property is duplicated).
"probes": [
{
"name": "FirstProbe",
"properties": {
"intervalInSeconds": 5,
"numberOfProbes": 2,
"port": 123,
"protocol": "Tcp"
}
},
{
"name": "SecondProbe",
"properties": {
"intervalInSeconds": 5,
"numberOfProbes": 2,
"port": 456,
"protocol": "Tcp"
}
}
],
"copy": [
{
"name": "probes",
"count": "[length(parameters('someParam'))]",
"input": {
"name": "[concat('OtherProbe', parameters('someParam')[copyindex('probes')])]",
"properties": {
"intervalInSeconds": 5,
"numberOfProbes": 2,
"port": "[parameters('someParam')[copyindex('probes')]]",
"protocol": "Tcp"
}
}
}
]
So in this case I need first two probes (FirstProbe and SecondProbe) to be explicitly defined but also I need more probes to be added based on someParam array values.
you just need to do this:
"variables": {
"probes-static": [
{
"name": "FirstProbe",
"properties": {
"intervalInSeconds": 5,
"numberOfProbes": 2,
"port": 123,
"protocol": "Tcp"
}
},
{
"name": "SecondProbe",
"properties": {
"intervalInSeconds": 5,
"numberOfProbes": 2,
"port": 456,
"protocol": "Tcp"
}
}
],
"copy": [
{
"name": "probes-loop",
"count": "[length(parameters('someParam'))]",
"input": {
"name": "[concat('OtherProbe', parameters('someParam')[copyindex('probes')])]",
"properties": {
"intervalInSeconds": 5,
"numberOfProbes": 2,
"port": "[parameters('someParam')[copyindex('probes')]]",
"protocol": "Tcp"
}
}
}
],
"probes": "[concat(variables('probes-static'), variables('probes-loop'))]"
}
and then you can use variable('probes') as the result and assign it to the LB property

Sylius ShopApiPlugin Can't add products to cart

I'am trying to add a product to my cart using the ShopApiPlugin made for Sylius.
When I try to add a product thru /carts/mytokenoid/items with the json body
{
"productCode": "iphone9",
"quantity": 5
}
I get this response
{
"tokenValue": "mytokenoid",
"channel": "US_WEB",
"currency": "EUR",
"locale": "en_US",
"checkoutState": "cart",
"items": [
{
"quantity": 5,
"total": 4800,
"product": {
"code": "iphone9",
"name": "iPhone 9",
"slug": "iphone-9",
"averageRating": 0,
"taxons": {
"others": []
},
"variants": [
{
"code": "iphone9",
"axis": [],
"nameAxis": [],
"price": {
"current": 2000,
"currency": "EUR"
},
"images": []
}
],
"attributes": [],
"associations": [],
"images": []
}
}
],
"totals": {
"total": 6896,
"items": 4800,
"taxes": 0,
"shipping": 2096,
"promotion": -5200
}, (...)
But when I do /shop-api/carts/mytokenoid to check my cart content, it is empty, nothing was added. Also I checked the database and the cart is there with the correct token but no items.
Does anyone know how can I solve this? I already tried with authorization token and without. Got the same thing
Found the solution.
You just have to uncomment the "- tactician.middleware.doctrine" line in the config/packages/league_tactician.yaml

API Platform filter entity data

I just start to use Api platform and immediately stuck with problem how to filter data.
I have entity User and i want to filter data that are present in response ( JSON API format)
{
"links": {
"self": "/api/users"
},
"meta": {
"totalItems": 2,
"itemsPerPage": 30,
"currentPage": 1
},
"data": [
{
"id": "/api/users/1",
"type": "User",
"attributes": {
"_id": 1,
"username": "jonhdoe",
"isActive": true,
"address": null
}
},
{
"id": "/api/users/3",
"type": "User",
"attributes": {
"_id": 3,
"username": "test",
"isActive": true,
"address": null
}
}
]
}
so I want to remove e.g. User with id 3, but not use filters sent via request. I just want to set filter that will be always run when someone go to /api/users.
I look to api-platform extensions but this will be applied on each request e.g. /api/trucks. So at end I just want to get something like
{
"links": {
"self": "/api/users"
},
"meta": {
"totalItems": 1,
"itemsPerPage": 30,
"currentPage": 1
},
"data": [
{
"id": "/api/users/1",
"type": "User",
"attributes": {
"_id": 1,
"username": "jonhdoe",
"isActive": true,
"address": null
}
}
]
}
As you pointed out, extensions are the way to go.
The applyToCollection method gets a $resourceClass parameter containing the current resource class.
So you can apply the WHERE clause only for a specific class in this method like:
public function applyToCollection(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, string $operationName = null)
{
if (User::class === $resourceClass) {
$queryBuilder->doSomething();
}
// Do nothing for other classes
}

It is possible to update item with only hash key in dynamoDB PHP? I Don't have range key value

Record1:
[{
"business_id": 2,
"user_id" = 5,
"forms": {
"f522": {
"id": "f522",
"is_deleted": 0,
"title": "Form 1"
},
"f8b6": {
"id": "f8b6",
"is_deleted": 0,
"title": "Form 2"
},
"fw56": {
"id": "fw56",
"is_deleted": 0,
"title": "Form 3"
}
}
}]
Record2:
[{
"business_id": 3,
"user_id" = 1,
"forms": {
"f788": {
"id": "f788",
"is_deleted": 0,
"title": "Form 11"
},
"f6yy": {
"id": "f6yy",
"is_deleted": 0,
"title": "Form 12"
},
"f00i": {
"id": "f00i",
"is_deleted": 0,
"title": "Form 13"
}
}
}]
Record3:
[{
"business_id": 4,
"user_id" = 3,
"forms": {
"f839": {
"id": "f839",
"is_deleted": 0,
"title": "Form 21"
},
"f1bc": {
"id": "f1bc",
"is_deleted": 0,
"title": "Form 22"
},
"f6ac": {
"id": "f6ac",
"is_deleted": 0,
"title": "Form 23"
}
}
}]
I have 3 records stored in dynamo-db table. Hash Key is business_id and range key is user_id. forms object is parent object with child objects(id, is_deleted, title). I don't know user_id value. But I have only business_id value "2"(Which is unique. not repeated in other record business_id). I want update record 2 is_deleted value to 1 of id(value is f6yy). If possible, Please suggest query.
No it is not possible.
But as an alternate route you can update whole value by replacing with new Value.
Firstly, AWS sdk for dynamodb requires both key values for the update operation, hence both keys are necessary because the entry can be identified only using both the keys.
Secondly: You mentioned
(Which is unique. not repeated in other record business_id)
If the mapping for user_id and business_id is such that no 2 users can have the same business_id then you may just use business_id as primary key and not use the user_id as a sort/range key (as it is optional to have a range key). The user_id field will still be there but it will not be a range key anymore.
If that is not the case then what u can do is again use only one key [the primary key (business_id) mentioned above] and store the user_id along with the forms object. I am assuming here that forms object is related to a user_id with a business_id.
The new schema will look something like this
{ "Record1": [
{
"business_id": 2,
"forms":
[
{
"user_id" : 5,
"f522": { "id": "f522", "is_deleted": 0, "title": "Form 1" },
"f8b6": { "id": "f8b6", "is_deleted": 0, "title": "Form 2" },
"fw56": { "id": "fw56", "is_deleted": 0, "title": "Form 3" }
}
]
}
]
}
The update operations now becomes non-trivial ,
so you will first have to get the entry.
update it yourself by iteration and making changes.
then use the update operation or a simple putItem with the new object.

Resources