The WeChat applet uses the third-party library Immutable. js instance for details, and the mini-program immutable. js

Source: Internet
Author: User

The mini-program uses the third-party library Immutable. js instance for details, the mini-program immutable. js

Preface

Immutable JS provides an inert Sequence that allows efficient queue method chains, such as map and filter, without creating intermediate representatives. Immutable provides Sequence, Range, Repeat, Map, OrderedMap, Set, and a sparse Vector through the inert queue and hash ing.

The applet cannot directly use require ('immutable. js') for calling. You need to modify the downloaded immutable code before using it.

Cause Analysis

Immutable uses UMD modular specifications

(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global.Immutable = factory());}(this, function () { 'use strict';var SLICE$0 = Array.prototype.slice;....}));

The implementation of UMD is very simple. First, determine whether the Node. js (CommonJS) module specification is supported. If so, use the Node. js (CommonJS) method to load the module. Determine whether AMD is supported, and use AMD to load modules. If neither of the first two does exist, the module is published to the global environment.

Both exports and module must be defined to load modules in CommonJS. Through the test, the program running environment exports and module are not defined.

Solution

Modify the Immutable code, comment out the Export Statement of the original module, and usemodule.exports = factory()Force Export

(function(global, factory) { /* typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global.Immutable = factory()); */ module.exports = factory();}(this, function() {

Use Immutable. js

// Index. jsvar Immutable = require ('.. /.. /libs/immutable. modified. js '); // obtain the application instance var app = getApp (); Page ({onLoad: function () {// console. log ('onload'); var that = this; var lines = []; lines. push ("var map1 = Immutable. map ({a: 1, B: 2, c: 3}); "); var map1 = Immutable. map ({a: 1, B: 2, c: 3}); lines. push ("var map2 = map1.set ('B', 50);"); var map2 = map1.set ('B', 50); lines. push ("map1.get ('B');"); lines. push (map1.get ('B'); lines. push ("map2.get ('B');"); lines. push (map2.get ('B'); this. setData ({text: lines. join ('\ n ')})}})

Summary

The above is all about this article. I hope to help you in your study or work. If you have any questions, please leave a message.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.