This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>My first application on the base of Matreshka</title> | |
| </head> | |
| <body> | |
| <input type="text" class="my-input"> | |
| <div class="my-output"></div> | |
| <script src="http://cdn.jsdelivr.net/matreshka/latest/matreshka.min.js"></script> | |
| <script src="js/app.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Application = Class({ | |
| 'extends': Matreshka, | |
| constructor: function() { | |
| // bind x property to the text field | |
| this.bindNode( 'x', '.my-input' ); | |
| // bind x property and block to my-output class | |
| this.bindNode( 'x', '.my-output', { | |
| setValue: function( v ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var data = [{ | |
| name: 'Ida T. Heath', | |
| email: 'ida@dayrep.com', | |
| phone: '507-879-9766' | |
| }, { | |
| name: 'Robert C. Burkhardt', | |
| email: 'rburkhardt@teleworm.us', | |
| phone: '321-252-5698' | |
| }, { | |
| name: 'Gerald S. Reaves', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Some math based on https://en.wikipedia.org/wiki/Discrete_logarithm | |
| // The function fastModularExponentiation allow to generate | |
| // pseudo-random unique number from 0 to prime - 1. | |
| // In other words every gotten number is converted to another number and returned numbers are unique | |
| // Warning! When number arg is more than prime then returned numbers are going to be repeated | |
| // thus for biggrer numbers we'll need to choose bigger prime number. | |
| // The implementation if fastModularExponentiation is taken there https://gist.github.com/krzkaczor/0bdba0ee9555659ae5fe | |
| // Primitive root calc: http://www.bluetulip.org/2014/programs/primitive.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| r=(f,d=document)=>d.readyState[0]=='l'?d.addEventListener('DOMContentLoad',f):f() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var orderBy = function(arr, keys, orders) { | |
| var defaultOrder = 'asc', | |
| newArr, | |
| length, | |
| i, | |
| commonOrder; | |
| if ('length' in arr && typeof arr == 'object') { | |
| if (!(orders instanceof Array)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const readCache = require('read-cache'); | |
| const fs = require('fs'); | |
| const { NodeVM, VMScript } = require('vm2'); | |
| const optional = require('optional'); | |
| /* | |
| The function enhances postcss import plugin allowing CSS files to @import JS files | |
| which, in their turn, import a valid PostCSS string. | |
| Example code: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| A bit of syntax sugar over context providers. Allows to turn code like this: | |
| <SomeProvider1> | |
| <SomeProvider2> | |
| <SomeProvider3> | |
| <MyComponent /> | |
| </SomeProvider3> | |
| </SomeProvider2> | |
| </SomeProvider1> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Usage: | |
| usePromiseEffect(async => () => { | |
| await fetch(foo); | |
| // ... | |
| }) | |
| */ | |
| import { useEffect } from 'react'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Usage: | |
| const [forceIndex, forceUpdate] = useForceUpdate(); | |
| // call forceUpdate() when component needs to be updated | |
| // use forceIndex as key to force re-render child components | |
| Important! This function is most likely an antipattern! But sometimes I can be super useful: | |
| it can re-render react native screens when something gone wrong and user is prompted by a "Try again" button. | |
| */ |
OlderNewer