ItemSeparatorComponent React Native - react-native

So, i'm using a separator in a flatlist. I linked the separator to a logging function that logs the key of each item in the flatlist. When i reload the app, the first 10 items are logged, then the first 20, etc... In fact every 10 items, the iteration restart and all items from the beginning are logged. But if i just save the code, the app is refreshed and all items are logged just once as i expected.
here is my code:
import React from 'react';
import { Text, View, StyleSheet, TextInput, FlatList } from 'react-native';
import { Constants } from 'expo';
import { useState} from "react";
export default function App() {
const [reviews, setReviews] = useState([
{key:'1'},
{key:'2'},
{key:'3'},
{key:'4'},
{key:'5'},
{key:'6'},
{key:'7'},
{key:'8'},
{key:'9'},
{key:'10'},
{key:'11'},
{key:'12'},
{key:'13'},
{key:'14'},
{key:'15'},
{key:'16'},
{key:'17'},
{key:'18'},
{key:'19'},
{key:'20'},
{key:'21'},
{key:'22'},
{key:'23'},
])
const separator=(e)=>{
console.log(e.leadingItem.key)
}
return (
<View >
<FlatList
ItemSeparatorComponent={(e)=>separator(e)}
data={reviews}
renderItem={({item}) => (
<Text>{item.key}</Text>
)}
/>
</View>
)
}
});
here is the logs when the app is reloaded
log : 1
log : 2
log : 3
log : 4
log : 5
log : 6
log : 7
log : 8
log : 9
log : 10
log : 1
log : 2
log : 3
log : 4
log : 5
log : 6
log : 7
log : 8
log : 9
log : 10
log : 11
log : 12
log : 13
log : 14
log : 15
log : 16
log : 17
log : 18
log : 19
log : 20
log : 1
log : 2
log : 3
log : 4
log : 5
log : 6
log : 7
log : 8
log : 9
log : 10
log : 11
log : 12
log : 13
log : 14
log : 15
log : 16
log : 17
log : 18
log : 19
log : 20
log : 21
log : 22
here is the logs when the app is refreshed
log : 1
log : 2
log : 3
log : 4
log : 5
log : 6
log : 7
log : 8
log : 9
log : 10
log : 11
log : 12
log : 13
log : 14
log : 15
log : 16
log : 17
log : 18
log : 19
log : 20
log : 21
log : 22
Is this behavior avoidable ?
If not will this behavior persist in production mode ?

If you want to render the ItemSeparatorComponent between every other set of items, rather than every 10 items, you can use the itemIndex prop passed to the ItemSeparatorComponent to determine when to render the separator. For example, you could use the following code to render the ItemSeparatorComponent between every other set of items:
function MyItemSeparator({ itemIndex }) {
if (itemIndex % 20 === 0) {
return <View style={styles.separator} />;
}
return null;
}
This code will render the ItemSeparatorComponent between every 20th item in the list (i.e., between the 0th item, the 20th item, the 40th item, etc.). You can adjust the modulus operator (%) to change the frequency with which the separator is rendered.

Related

istanbul generates empty report

I wanted to launch istanbul in my project, however no matter what I do reports shows only zeros. like below :
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 0 | 0 | 0 | 0 |
----------|---------|----------|---------|---------|-------------------
Even though it shows above the coverage report list of the test that passed. For simplicity I created super simple project for replication where I have only one function in indentity.js file :
export const identity = (x) => x;
and one simple test licated in test.js file
import { identity } from "./identity.js";
import assert from "assert";
describe("identity", function () {
it("should return passed argument", () => {
assert.equal(identity(1), 1);
assert.equal(identity("string"), "string");
assert.deepEqual(identity({ a: 1 }), { a: 1 });
});
});
and after I run nyc mocha I expect to see 100% coverage but what I have is the same table with zeros.
Is there some settings I missed to see proper coverage report ?
Thx in advance.

react on a supply from a sequence

I can't understand why this program works:
my $supply = Supply.interval: 1;
react {
whenever $supply { put "Got $^a" }
whenever Promise.in(5) { put 'Timeout!'; done }
}
END put 'Ending…'
printing this:
Got 0
Got 1
Got 2
Got 3
Got 4
Timeout!
Ending…
and exits correctly, while this one:
my $supply = (1, 1, * + * … ∞).Supply;
react {
whenever $supply { put "Got $^a"; sleep 1 }
whenever Promise.in(5) { put 'Timeout!'; done }
}
END put 'Ending…'
prints
Got 1
Got 1
Got 2
Got 3
Got 5
Timeout!
but then it hangs and doesn't output the "Ending…"; isn't the "done" enough in this case?
If I replace "done" with "exit" the program works fine and exits.

NativeScript-Vue [node-rsa] TypeError: util.inherits is not a function

When trying to include node-rsa got:
TypeError: util.inherits is not a function.
Repro steps:
vue init nativescript-vue/vue-cli-template repro
cd repro
npm install --save node-rsa
npm install
Add this line to HelloWorld.vue:
<script>
import * as NodeRSA from "node-rsa"; // add this line
export default {
data () {
return {
surprise: false,
};
},
};
</script>
npm run watch:ios
Got this error:
***** Fatal JavaScript exception - application has been terminated. *****
Native stack trace:
1 0x104692c1f NativeScript::reportFatalErrorBeforeShutdown(JSC::ExecState*, JSC::Exception*, bool, bool)
2 0x1046c7caf -[TNSRuntime executeModule:referredBy:]
3 0x10414b441 main
4 0x10a137955 start
5 0x1
JavaScript stack trace:
1 #file:///app/app.js:13604:14
2 __webpack_require__#file:///app/app.js:20:34
3 #file:///app/app.js:36341:33
4 #file:///app/app.js:36601:34
5 __webpack_require__#file:///app/app.js:20:34
6 #file:///app/app.js:36311:33
7 __webpack_require__#file:///app/app.js:20:34
8 #file:///app/app.js:9649:30
9 __webpack_require__#file:///app/app.js:20:34
10 #file:///app/app.js:27449:30
11 #file:///app/app.js:27838:34
12 __webpack_require__#file:///app/app.js:20:34
13 #file:///app/app.js:27406:35
14 __webpack_require__#file:///app/app.js:20:34
15 #file:///app/app.js:27228:176
16 __webpack_require__#file:///app/app.js:20:34
17 #file:///app/app.js:13948:38
18 __webpack_require__#file:///app/app.js:20:34
19 #file:///app/app.js:63:37
20 anonymous#file:///app/app.js:64:12
21 evaluate#[native code]
22 moduleEvaluation#[native code]
23 #[native code]
24 promiseReactionJob#[native code]
JavaScript error:
file:///app/app.js:13604:14: JS ERROR TypeError: util.inherits is not a function. (In 'util.inherits(assert.AssertionError, Error)', 'util.inherits' is an instance of Object)

CreateJS : MovieClip.children doesn't update after gotoAndStop()

CreateJS (2015.11.26) via Animate CC (16.0.0.112)
Structure :
root
- myContainer
- frame 0 -> btn_0
- frame 1 -> btn_1
First frame of root contains following code :
var self = this;
createjs.Ticker.addEventListener("tick", initScreen);
function initScreen() {
createjs.Ticker.removeEventListener("tick", initScreen);
self.myContainer.gotoAndStop(1);
}
this.myContainer.addEventListener("click", function(e) {
console.log("Button 0 : "+self.myContainer.btn_0);
console.log("Button 1 : "+self.myContainer.btn_1);
});
The result is :
[Log] Button 0 : [MovieClip]
[Log] Button 1 : undefined
And when iterating through self.myContainer.children, only btn_0 exists.
So self.myContainer.children is not being updated when playing through the frames.
Seems like a bug, as I can't find any documentation around this... but I'm surprised that I can't find anyone else who's had this issue.
Any help much appreciated.
(Issue raised here : https://github.com/CreateJS/EaselJS/issues/848)
I believe this is because both buttons use the same symbol.
In AnimateCC, choose btn_1 and change its "instance of", by swapping-duplicating to a new symbol.
This logged for me:
Button 0 : [MovieClip (name=null)]
Button 1 : [MovieClip (name=null)]

Passing Argument to Specific Function in STAX Job Using Command Line

I have a STAX Job new15.xml inside /home/dharm/staf/services/stax/samples location.
new15.xml have two function main and readFile
file_name = '/home/dharm/datafiles/ReadData3.txt'
Required Argument for readFile is file_name.
I want to execute this command using command line but i also want to give required parameter to readFile function.
staf local execute file /home/dharm/staf/services/stax/samples/new15.xml wait return result
What are the modification i should do in command to make it work.
"What I have Trierd"
FIRST
dharm#ubuntu:~$ staf local stax execute file /home/dharm/staf/services/stax/samples/new15.xml ARGS file_name="'/home/dharm/datafiles/ReadData3.txt'" wait returnresult
Response
--------
{
Job ID : 3
Start Date-Time: 20130418-23:54:39
End Date-Time : 20130418-23:54:40
Status : Terminated
Result : None
Job Log Errors : [
{
Date-Time: 20130418-23:54:40
Level : Error
Message : STAXPythonEvaluationError signal raised. Terminating job.
===== XML Information =====
File: /home/dharm/staf/services/stax/samples/new15.xml, Machine: local://local
Line <Error in ARGS option>: Error in element type "<External>".
===== Python Error Information =====
com.ibm.staf.service.stax.STAXPythonEvaluationException:
Python object evaluation failed for:
file_name='/home/dharm/datafiles/ReadData3.txt'
SyntaxError: ("mismatched input '=' expecting EOF", ('<pyEval string>', 1, 9, "file_name='/home/dharm/datafiles/ReadData3.txt'\n"))
===== Call Stack for STAX Thread 1 =====
[]
}
]
Testcase Totals: {
Tests : 0
Passes: 0
Fails : 0
}
}
"2ND Command"
dharm#ubuntu:~$ staf local stax execute file /home/dharm/staf/services/stax/samples/new15.xml SCRIPT file_name="'/home/dharm/datafiles/ReadData3.txt'" wait returnresult
Response
--------
{
Job ID : 4
Start Date-Time: 20130418-23:56:01
End Date-Time : 20130418-23:56:02
Status : Terminated
Result : None
Job Log Errors : [
{
Date-Time: 20130418-23:56:02
Level : Error
Message : STAXFunctionArgValidate signal raised. Terminating job.
===== XML Information =====
File: /home/dharm/staf/services/stax/samples/new15.xml, Machine: local://local
Line 20: Error in element type "call".
Required argument "file_name" is not provided in the call to function "readFile".
===== Call Stack for STAX Thread 1 =====
[
function: main (Line: 19, File: /home/dharm/staf/services/stax/samples/new15.xml, Machine: local://local)
]
}
]
Testcase Totals: {
Tests : 0
Passes: 0
Fails : 0
}
}