Skip to content

Commit d2aea31

Browse files
authored
Merge pull request #1 from davidchin/add_function
CHECKOUT-4272: Add `memoize` function
2 parents 2d9eb84 + bca0389 commit d2aea31

21 files changed

+7476
-0
lines changed

.circleci/config.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
version: 2.1
2+
3+
orbs:
4+
ci: bigcommerce/internal@volatile
5+
node: bigcommerce/internal-node@volatile
6+
7+
jobs:
8+
build:
9+
executor:
10+
name: node/node
11+
node-version: "10"
12+
13+
steps:
14+
- ci/pre-setup
15+
16+
- restore_cache:
17+
keys:
18+
- memoize-js
19+
20+
- run: npm ci
21+
22+
- save_cache:
23+
key: memoize-js
24+
paths:
25+
- ~/.npm
26+
27+
- run:
28+
name: Test
29+
command: npm run test:series -- --coverage
30+
when: always
31+
32+
- store_artifacts:
33+
path: coverage
34+
destination: coverage
35+
36+
- run:
37+
name: Lint
38+
command: npm run lint
39+
when: always
40+
41+
- run:
42+
name: Validate commits
43+
command: npm run validate-commits
44+
when: always

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## What?
2+
...
3+
4+
## Why?
5+
...
6+
7+
## Testing / Proof
8+
...
9+
10+
@bigcommerce/frontend

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.log
2+
/coverage
3+
/lib
4+
/node_modules

CODE_OF_CONDUCT.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6+
7+
## Our Standards
8+
9+
Examples of behavior that contributes to creating a positive environment include:
10+
11+
* Using welcoming and inclusive language
12+
* Being respectful of differing viewpoints and experiences
13+
* Gracefully accepting constructive criticism
14+
* Focusing on what is best for the community
15+
* Showing empathy towards other community members
16+
17+
Examples of unacceptable behavior by participants include:
18+
19+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
20+
* Trolling, insulting/derogatory comments, and personal or political attacks
21+
* Public or private harassment
22+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
23+
* Other conduct which could reasonably be considered inappropriate in a professional setting
24+
25+
## Our Responsibilities
26+
27+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28+
29+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30+
31+
## Scope
32+
33+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34+
35+
## Enforcement
36+
37+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [email protected]. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38+
39+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40+
41+
## Attribution
42+
43+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44+
45+
[homepage]: http://contributor-covenant.org
46+
[version]: http://contributor-covenant.org/version/1/4/

CONTRIBUTING.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Contributing
2+
3+
## Issues / Bugs
4+
5+
* Please include a clear, specific title and replicable description.
6+
7+
* Please include your environment, OS, and any exceptions/backtraces that occur. The more
8+
information that is given, the more likely we can debug and fix the issue.
9+
10+
**If you find a security bug, please do not post as an issue. Send directly to [email protected]
11+
instead.**

LICENSE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(The MIT License)
2+
Copyright (C) 2018-Present BigCommerce Inc.
3+
All rights reserved.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,50 @@
1+
# @bigcommerce/memoize
12

3+
This library can be used to memoize the result of a pure function.
4+
5+
Unlike the default `memoize` function provided by Lodash, it can be applied to functions that accept multiple non-primitive arguments. It can also be configured to expire its cache after certain number of unique calls. By default, it compares object-based arguments shallowly; but it can be configured to compare arguments strictly or deeply depending on your usage requirement.
6+
7+
8+
## Install
9+
10+
You can install this library using [npm](https://www.npmjs.com/get-npm).
11+
12+
```sh
13+
npm install --save @bigcommerce/memoize
14+
```
15+
16+
17+
## Usage
18+
19+
To memoize a function
20+
21+
```ts
22+
function fn(a, b) {
23+
return { a, b };
24+
}
25+
26+
const memoizedFn = memoize(fn);
27+
const result = memoizedFn({ message: 'hello' }, { message: 'world' });
28+
const result2 = memoizedFn({ message: 'hello' }, { message: 'world' });
29+
30+
expect(result).toBe(result2);
31+
```
32+
33+
34+
## Contribution
35+
36+
To release:
37+
38+
```sh
39+
npm run release
40+
```
41+
42+
To see other available commands:
43+
44+
```sh
45+
npm run
46+
```
47+
48+
## License
49+
50+
MIT

commit-validation.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"scopes": [
3+
"common",
4+
"core"
5+
]
6+
}

jest-config.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module.exports = {
2+
browser: true,
3+
preset: 'ts-jest',
4+
moduleFileExtensions: [
5+
'ts',
6+
'tsx',
7+
'js',
8+
'jsx',
9+
'json',
10+
],
11+
setupTestFrameworkScriptFile: '<rootDir>/jest-setup.ts',
12+
collectCoverageFrom: [
13+
'src/**/*.ts',
14+
],
15+
coveragePathIgnorePatterns: [
16+
'\\.mock\\.ts$',
17+
'\\.d\\.ts$',
18+
],
19+
};

jest-setup.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
beforeAll(() => {
2+
expect.hasAssertions();
3+
});

0 commit comments

Comments
 (0)