npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-sk-datasource-accessor-mixin

v1.0.2

Published

Mixin which can easily manipulate ListViewDataSource, for example: 1 add row 2 delete row 3 get rows 4 count rows

Downloads

2

Readme

react-native-sk-datasource-accessor-mixin

##What is it

react-native-sk-datasource-accessor-mixin is a mixin which can easily manipulate ListViewDataSource.

First of all, let's study ListViewDataSource:

ListViewDataSource is composed of several rows, it use three fields to descript these rows:

| Prop | Description | Default | |---|---|---| |sectionIdentities|An array of identifiers for sections, which tell the render order of sections. |None| |rowIdentities|A 2D array of identifiers for rows, which tell the render order of rows. |None| |dataBlob|An map of data for sectionIdentities and rowIdentities, its data structure is <sectionID: <rowID: row>>. |None|

Second, we normally use json data in our application, and I want to convert json to ListViewDataSource's fields.

So, here comes react-native-sk-datasource-accessor-mixin:

1 It offer several methods to manipuldate rows of ListViewDataSource.

for example: 1 appendRows(newRows) 2 deleteRow(row)

2 It accept json array and converts json array into dataBlob and rowIdentities of ListViewDataSource. (Temporarily not handle sectionIdentities).

##How to use it

  1. npm install react-native-sk-datasource-accessor-mixin@latest --save

  2. Write this in index.ios.js / index.android.js


'use strict';
import React, {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  ListView,
  TouchableHighlight
} from 'react-native';

var DataSourceAccessorMixin = require('react-native-sk-datasource-accessor-mixin');

var test = React.createClass({

  mixins: [DataSourceAccessorMixin], // 1 inherit the mixin

  _idField: 'id', // 2 declare '_idField',  name of field which represents row's ID

  getInitialState(){
    return {
      dataSource: new ListView.DataSource({ // 3 declare a dataSource state first, it will be used in DataSourceAccessorMixin
        rowHasChanged:(row1, row2) => {
          return row1 !== row2;
        }
      }),
    };
  },

  // prepare json data
  componentDidMount(){
   //  var rows = [
   //   {id: 1, text: 'row 1'},
   //   {id: 2, text: 'row 2'},
   //   {id: 3, text: 'row 3'},
   //   {id: 4, text: 'row 4'},
   //   {id: 5, text: 'row 5'},
   //   {id: 6, text: 'row 6'},
   //   {id: 7, text: 'row 7'},
   //   {id: 8, text: 'row 8'},
   //   {id: 9, text: 'row 9'},
   //  ];
    var rows = [];
    for(var i = 0; i < 10; i++){
      rows.push({id: i, text: 'row ' + i},)
    }
    this.setRows(rows);
  },

  onPressRow(row) {
    console.log(row+' pressed');
    this.currRow = row;
  },

  renderRow(row) {
    return (
      <TouchableHighlight
        style={styles.row}
        underlayColor='#c8c7cc'
        onPress={() => this.onPressRow(row)}
      >
        <Text>{row.text}</Text>
      </TouchableHighlight>
    );
  },

 onAppendRow(){
   var n = this.rowCount();
   this.appendRow({id: n, text: 'row ' + n}) // append a row
 },

 onDeleteRow(){
   if(!this.currRow){
     console.log('no selected row');
     return;
   }
   this.deleteRow(this.currRow) // delete a row
 },

  render() {
    return (
      <View style={styles.container}>
        <ListView
         dataSource={this.state.dataSource} // 4 use the dataSource state in listview
         renderRow={this.renderRow}
       />
       <View style={styles.btnBox}>
         <TouchableHighlight
           style={styles.btn}
           underlayColor='#c8c7cc'
           onPress={this.onAppendRow}
         >
           <Text>append row</Text>
         </TouchableHighlight>
         <TouchableHighlight
           style={styles.btn}
           underlayColor='#c8c7cc'
           onPress={this.onDeleteRow}
         >
           <Text>delete row</Text>
         </TouchableHighlight>
       </View>
      </View>
    );
  }
});

var styles = {
  container: {
    flex: 1,
    backgroundColor: '#FFF',
  },
  row: {
    padding: 10,
    height: 44,
    backgroundColor: 'yellow',
    borderBottomColor: 'grey',
    borderBottomWidth: 2,
  },
  btnBox: {
    flexDirection: 'row',
    justifyContent: 'space-around',
    height: 44,
  },
  btn: {
    width: 90,
    height: 40,
    backgroundColor: 'grey',
    justifyContent: 'center',
    alignItems: 'center',
    borderRadius: 5,
  }
};

AppRegistry.registerComponent('test', () => test);

##Methods

| Method | Description | Params | |---|---|---| |idField()|Get name of field which represents row's ID. |None| |isEmpty()|Whether there is no rows. |None| |rowCount()|Count of rows. |None| |rows()|Get rows. |None| |rowIds()|Get row's IDs. |None| |setRows(newRows)|Set rows. |None| |appendRows(newRows)|Insert multiple rows at the end. |None| |prependRows(newRows)|Insert multiple rows in the head. |None| |appendRow(newRow)|Insert one row at the end. |None| |prependRow(newRow)|Insert one row in the head. |None| |deleteRow(row)|Delete row by ID. |None|