simple-squiggle

A restricted subset of Squiggle
Log | Files | Refs | README

custom_loading.js (850B)


      1 import {
      2   create,
      3   fractionDependencies,
      4   addDependencies,
      5   divideDependencies,
      6   formatDependencies
      7 } from '../..'
      8 
      9 const config = {
     10   // optionally, you can specify configuration
     11 }
     12 
     13 // Create just the functions we need
     14 const { fraction, add, divide, format } = create({
     15   fractionDependencies,
     16   addDependencies,
     17   divideDependencies,
     18   formatDependencies
     19 }, config)
     20 
     21 // Use the created functions
     22 const a = fraction(1, 3)
     23 const b = fraction(3, 7)
     24 const c = add(a, b)
     25 const d = divide(a, b)
     26 console.log('c =', format(c)) // outputs "c = 16/21"
     27 console.log('d =', format(d)) // outputs "d = 7/9"
     28 
     29 // Now, when bundling your application for use in the browser, only the used
     30 // parts of math.js will be bundled. For example to create a bundle using Webpack:
     31 //
     32 //     npx webpack custom_loading.js -o custom_loading.bundle.js --mode=production
     33 //