how to access qml ContextProperty variable in ListItemComponent of ListView - blackberry

I have problem to access exposed qml context Property variable in ListItemComponent.
e.g
applicationUI class:
qml->setcontextProperty("activeFrame",mActiveFrame);
main.qml
ListView{
id:model
listItemComponents: [
ListItemComponent {
id: listComponent
type:"item"
customListItem{
// here,i want to update cover.
// but error occur ,ReferenceError: Can't find variable: activeFrame
onPlayerStarted:{
activeFrame.isPlaying(true)
}
onPlayerStopped:{
activeFrame.isPlaying(false)
}
}
}
]
}
thanks

I found a solution.
To use activeFrame in ListitemComponent, we have to make new function in listview and call from customListItem.
ListView{
id:model
listItemComponents: [
ListItemComponent {
id: listComponent
type:"item"
customListItem{
id:listItem
onPlayerStarted:{
listItem.ListItem.view.playingActiveFrame();
}
onPlayerStopped:{
listItem.ListItem.view.resetActiveFrame();
}
}
}
]
function playingActiveFrame(){
activeFrame.isPlaying(true);
}
function resetActiveFrame(){
activeFrame.isPlaying(false);
}
}

Haven't tested, but something like this should work.
ListView{
id:model
listItemComponents: [
ListItemComponent {
id: listComponent
type:"item"
customListItem{
id:listItem
onPlayerStarted:{
listItem.ListItem.view.activeFrame.isPlaying(true)
}
onPlayerStopped:{
listItem.ListItem.view.activeFrame.isPlaying(false)
}
}
}
]
}
Because:
For some odd reason the listItemComponents are outside of the normal
code flow. But you can work around it. Give your listItemComponent a
name/id. Then you can reference trough the the parent ListView.
Source

Related

How to update connection metadata in client-side store?

I'm attempting to learn Relay by implementing TodoMVC from scratch.
I can query my data like this which is working well:
query {
allTodos(first: 100) {
totalCount
completedCount
edges {
node {
id
text
completed
}
}
}
}
I got the idea to add the totalCount and completedCount metadata to the connection from here: http://graphql.org/learn/pagination/#end-of-list-counts-and-connections
It's similar in this example: https://github.com/graphql/swapi-graphql/blob/master/src/schema/index.js#L78
Now I am writing a mutation to change the completed field of a Todo given its id.
I gather I will need to return the new completedCount in the mutation payload, but I'm not sure how to implement getConfigs() to update this in the client-side store. I don't have an id for the connection, right? Is there is a flaw in my schema design? Thanks!
Assuming your mutation returns a viewer, you'll need to add the viewer to your fatQuery and getConfigs. I think this tutorial might be helpful. Here's the excerpt relevant to your task:
Adding a Todo is more complex. The reason for this is that we need to
update not only the state of a Todo object that we will create, but
also a connection where it is stored - the count of Todos will change,
as well as the listing of Todo nodes in edges.
import Relay from 'react-relay';
export default class AddTodoMutation extends Relay.Mutation {
static fragments = {
viewer: () => Relay.QL`fragment on ReindexViewer {
id
allTodos {
count,
}
}`
};
getMutation() {
return Relay.QL`mutation{ createTodo }`;
}
getVariables() {
return {
text: this.props.text,
complete: false,
};
}
getFatQuery() {
return Relay.QL`
fragment on _TodoPayload {
changedTodoEdge,
viewer {
id,
allTodos {
count
}
}
}
`;
}
getConfigs() {
return [{
type: 'RANGE_ADD',
parentID: this.props.viewer.id,
connectionName: 'allTodos',
edgeName: 'changedTodoEdge',
rangeBehaviors: {
'': 'prepend',
},
}, {
type: 'FIELDS_CHANGE',
fieldIDs: {
viewer: this.props.viewer.id,
},
}];
}
getOptimisticResponse() {
return {
changedTodoEdge: {
node: {
text: this.props.text,
complete: false,
},
},
viewer: {
id: this.props.viewer.id,
allTodos: {
count: this.props.viewer.allTodos.count + 1,
},
},
};
}
}
In order to perform this mutation, we need some data that might not be
available to the component - the id of viewer object and count of
allTodos connection. Therefore we need to specify fragments for the
mutation same way as we specify them for containers.
Our configs are more complex this time too - we need to add our new
Todo to a connection, so we use RANGE_ADD mutation config. Relay
expects an edge to be passed in payload, not just a Todo, Reindex
provides changedTodoEdge for this. Lastly we need to fetch updated
connection count from the server and for this viewer field is
available for every payload.
In our optimistic update we increment the count of allTodos, so that
we change our “total” display without any delay.

Writing into JSON file iOS Swift

I have JSON file locally in my app. I want to add new element in this file programmatically. Below is my JSON format -
{
"MENU":{
"SUBMENU":[
{
"name":"name1",
"link":"link2"
}
]
}
}
I want to add another element in SUBMENU like below -
{
"MENU":{
"SUBMENU":[
{
"name":"name1",
"link":"link1"
},
{
"name":"name2",
"link":"link2"
}
]
}
}
Would it be possible to do it programatically? Thank!

Gatling - Retrieve part of json and check equality

I'm using Gatling tool to load test my service.
I have following response from my server(just an example):
{
"result: {
"288249": {
"allowEdit": 1,
"cells": [
{
"rollupId": "288249",
"description": "Gatling description: 93"
},
{
"rollupId": "288249",
"description": "Gatling description: 83"
}
]
}
}
}
What I need is loop thought all $.result.288249.cells[*].description fields and verify that there's a value, which is equal to what I have in one of my session objects.
It should look similar to following pseudo code:
.check(
jsonPath("$.result.*.cells[*].description").contains("${mySessionValue})
)
Is there are method, which I can use in similar way ?
Thanks in advance!
I think, I've found the solution
.check(
jsonPath("$.result.*.cells[?(#.description == '${mySessionValue}')]")
.find
.exists
)
This should do the work.
You can loop thru as follows
$.each($.result, function(index,obj){
$.each(obj['cells'], function(innerInd, innerObj){
if( ${mySessionValue} == innerObj['description'] )
{
console.log('Found')
return
}
})
})

Client-side mutation with RANGE_ADD type doesn't include edge inside request payload

I'm trying to create new object using client-side mutation described below:
import Relay from 'react-relay'
export default class CreateThemeMutation extends Relay.Mutation {
static fragments = {
admin: () => Relay.QL`fragment on Admin { id }`,
};
getMutation() {
return Relay.QL`mutation { createTheme }`
}
getFatQuery() {
return Relay.QL`
fragment on CreateThemePayload {
admin { themes }
themeEdge
}
`
}
getVariables() {
return {
name: this.props.name,
}
}
getConfigs() {
return [{
type: 'RANGE_ADD',
parentName: 'admin',
parentID: this.props.admin.id,
connectionName: 'themes',
edgeName: 'themeEdge',
rangeBehaviors: {
'': 'append',
},
}]
}
}
Root query field admin is quite similar to viewer so this shouldn't be a problem. The problem is I haven't found themeEdge (which I believe should present) within the request payload (admin { themes } is there though):
query: "mutation CreateThemeMutation($input_0:CreateThemeInput!){createTheme(input:$input_0){clientMutationId,...F3}} fragment F0 on Admin{id} fragment F1 on Admin{id,...F0} fragment F2 on Admin{_themes2gcwoM:themes(first:20,query:""){count,pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},edges{node{id,name,createdAt},cursor}},id,...F1} fragment F3 on CreateThemePayload{admin{id,...F0,id,...F2}}"
variables: {input_0: {name: "test", clientMutationId: "0"}}
As a result outputFields.themeEdge.resolve inside the server-side mutation never get called and I see this message:
Warning: writeRelayUpdatePayload(): Expected response payload to include the newly created edge `themeEdge` and its `node` field. Did you forget to update the `RANGE_ADD` mutation config?
I've seen similar issue on github. However REQUIRED_CHILDREN isn't my case because the application has requested themes connection already. Am I missing something obvious? Should I paste more info? Thanks.
react-relay version: 0.6.1
I ran into the same issue and eventually solved it by making sure that my equivalent of themeEdge actually existed as an edge in my schema. If you grep your schema for themeEdge, does an object exist?
For reference, here's my edge definition tailored for you:
{
"name":"themeEdge",
"description":null,
"args":[],
"type":{
"kind":"NON_NULL",
"name":null,
"ofType":{
"kind":"OBJECT",
"name":"ThemeEdge",
"ofType":null
}
},
"isDeprecated":false,
"deprecationReason":null
}
and
{
"kind":"OBJECT",
"name":"ThemeEdge",
"description":"An edge in a connection.",
"fields":[{
"name":"node",
"description":"The item at the end of the edge.",
"args":[],
"type":{
"kind":"NON_NULL",
"name":null,
"ofType":{
"kind":"OBJECT",
"name":"Theme",
"ofType":null
}
},
"isDeprecated":false,
"deprecationReason":null
}
Also note that your rangeBehaviors must exactly match the query you use to retrieve your parent object. You can specify multiple queries as follows, which also shows the syntax for when your query contains multiple variables:
{
type: 'RANGE_ADD',
parentName: 'admin',
parentID: this.props.admin.id,
connectionName: 'themes',
edgeName: 'themeEdge',
rangeBehaviors: {
'': 'append',
'first(1).id($adminId)': 'append',
},
}

Return data & reference from falcor router

I've got a route that returns details about a features on a user's account:
// games[{keys:games}].features[{integers:indices}]
{
$type : "atom",
value : {
id: "6",
count: "1",
...
}
}
There's also a route that returns generic details about specific features:
// features[{integers:features}]
{
$type : "atom",
value : {
name : "fooga",
max : 10,
...
}
}
I don't want to merge the generic feature data into the user-specific data because that will be a bunch of data duplication, but I also want to be able to get it all in a single request
What's a smart way to structure my routes/returned data so that games[{keys:games}].features[{integers:indices}] can return a useful reference to features[{integers:features}]?
I tried splitting them up like this:
// games[{keys:games}].features[{integers:indices}].details
{
$type : "atom",
value : {
id: "6",
count: "1",
...
}
}
// games[{keys:games}].features[{integers:indices}].meta
{
$type : "ref",
value : [
"features",
"15"
]
}
but I couldn't figure out a way to resolve the .meta reference w/o writing redundant-seeming paths like ...features.0.meta.[name,max,...]. Ideally the ref would just return an atom because it's a small amount of data.
I ended up structuring it like this:
games[{keys:games}].features[{integers:indices}].details
games[{keys:games}].features[{integers:indices}].feature
features[{keys:games}][{integers:features}].details
Ugly paths, but ¯\_(ツ)_/¯

Resources