比较React Native中的对象

时间:2015-05-12 15:17:05

标签: react-native

如何检查两个JavaScript值是否相同?

如果它们是对象,我想以递归的方式逐个比较它们。

我正在寻找一个现有的功能,而不是像我在这个问题中所描述的那样编写自己的功能:Object comparison in JavaScript

3 个答案:

答案 0 :(得分:2)

这是一个名为deepDiffer的功能。

答案 1 :(得分:0)

花点时间搜索一下如何导入deepDiffer

import deepDiffer from 'react-native/lib/deepDiffer'

...

deepDiffer(obj1, obj2) // true or false

答案 2 :(得分:0)

在React native> = 0.62.2中使用

const app = require('express')();
const server = require('http').createServer(app);
global.io = require('socket.io')(server);
const next = require('next');
const ip = require('ip');
const bonjour = require('bonjour')();
const dev = process.env.NODE_ENV !== 'production';
const nextApp = next({ dev });
const handle = nextApp.getRequestHandler();

io.on('connection', socket => {
  global.socket = socket;
  console.log('Connection');

  socket.on('streamCastLogs', () => {
    castLogger.stream({ start: -1 }).on('log', function (log) {
      global.socket.emit('castLog', { message: log.message, timestamp: log.timestamp });
    });
  });
});

nextApp.prepare().then(async () => {
  const port = config.get('port').value();

 app.all('*', (req, res) => { .... }

  server.listen(port, err => {
    if (err) throw err;

    // Publish a bonjour service
    const service = bonjour.publish({
      name: 'Assistant Relay',
      host: 'ar.local',
      type: 'http',
      port: port,
    });

    console.log(
      chalk.green.bold(
        `Visit http://${ip.address()}:${port} or http://${
          service.host
        }:${port} in a browser to configure`,
      ),
    );
  });
});