DoneJS StealJS jQuery ++ FuncUnit DocumentJS
3.0.0
2.3.27

 

  • Github
  • Twitter
  • Chat
  • Forum
  • Guides
  • Core
    • can-component
    • can-compute
    • can-connect
    • can-define
    • can-define/list/list
    • can-define/map/map
    • can-route
    • can-route-pushstate
    • can-set
      • types
        • Set
        • Compares
        • Prop
      • properties
        • Algebra
          • prototype
            • difference
            • equal
            • getSubset
            • getUnion
            • has
            • index
            • intersection
            • properSubset
            • subset
            • union
        • Translate
        • props
    • can-stache
    • can-stache/helpers/route
    • can-stache-bindings
  • Ecosystem
  • Infrastructure
  • Legacy
  • Bitovi
    • Bitovi.com
    • Blog
    • Consulting
    • Training
    • Open Source
  • Chat
  • Forum
  • Star
  • Follow @canjs
  • CanJS
  • /
  • Core
  • /
  • can-set
  • /
  • Algebra
  • / On this page
    • Algebra

      function

      Perform set logic with an awareness of how certain properties represent a set.

      • source

      new set.Algebra(compares...)

      An algebra instance can perform a variety of set logic methods using the compares configuration.

      A default algebra instance can be created like:

      var set = require("can-set");
      var defaultAlgebra = new set.Algebra();
      

      This treats every property as a filter in a where clause. For example:

      // `{id: 2, ownerId: 5}` belongs to ``.getList({ownerId: 5})`
      defaultAlgebra.has({ownerId: 5}, {id: 2, ownerId: 5}) //-> true
      
      defaultAlgebra.getSubset({ownerId: 5}, {},
          [
              {id: 1, ownerId: 2},
              {id: 2, ownerId: 5},
              {id: 3, ownerId: 12}
          ]) //-> [{id: 2, ownerId: 5}]
      

      Compares configurations can be passed to add better property behavior awareness:

      var set = require("can-set");
      var todoAlgebra = new set.Algebra(
        set.props.boolean("completed"),
        set.props.id("_id"),
        set.props.offsetLimit("offset","limit")
      );
      
      defaultAlgebra.getSubset({limit: 2, offset: 1}, {},
          [
              {id: 1, ownerId: 2},
              {id: 2, ownerId: 5},
              {id: 3, ownerId: 12}
          ]) //-> [{id: 2, ownerId: 5},{id: 3, ownerId: 12}]
      

      props has helper functions that make common Compares configurations.

      Parameters

      1. compares {Compares}:

        Each argument is a compares. These are returned by the functions on props or can be created manually.

      Returns

      {Algebra(compares)}:

      Returns an instance of an algebra.

      CanJS is part of DoneJS. Created and maintained by the core DoneJS team and Bitovi. Currently 3.0.0.